|
@@ -30,6 +30,15 @@ impl Record {
|
|
|
pub fn size(&self) -> usize {
|
|
|
self.fields.len()
|
|
|
}
|
|
|
+
|
|
|
+ pub fn get(&self, key: &str) -> Option<&str> {
|
|
|
+ for (f, v) in self.fields.iter() {
|
|
|
+ if f == key {
|
|
|
+ return Some(v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ None
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
|
@@ -55,9 +64,13 @@ impl Recfile {
|
|
|
None => false,
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ pub fn iter(&self) -> impl Iterator<Item=&Record> {
|
|
|
+ self.records.iter()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-#[derive(Debug, Fail)]
|
|
|
+#[derive(Debug, Fail, PartialEq, Eq)]
|
|
|
pub enum RecError {
|
|
|
#[fail(display = "Error parsing records: {}", message)]
|
|
|
GenericError { message: String },
|
|
@@ -131,7 +144,7 @@ impl Recfile {
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
- use {Recfile, Record};
|
|
|
+ use {Recfile, RecError, Record};
|
|
|
|
|
|
fn test_parse(input: &[u8], expected: Vec<Vec<(&str, &str)>>) {
|
|
|
let file = Recfile {
|
|
@@ -146,7 +159,7 @@ mod tests {
|
|
|
})
|
|
|
.collect(),
|
|
|
};
|
|
|
- assert_eq!(Recfile::parse(input), Ok(file));
|
|
|
+ assert_eq!(Recfile::parse(input).unwrap(), file);
|
|
|
}
|
|
|
|
|
|
#[test]
|