1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::chopper::types::{Header, Row};
pub fn check_header(header: &Header) -> Result<usize, String> {
let field_types_count = header.field_types().len();
let field_names_count = header.field_names().len();
if field_names_count != field_types_count {
return Err(format!(
"there are {} field types but {} field names; expected them to be same",
field_types_count, field_names_count
));
}
Ok(field_types_count)
}
pub fn check_row(row: impl AsRef<Row>, expected_field_count: usize) -> Result<(), String> {
let row = row.as_ref();
if row.field_values.len() == expected_field_count {
Ok(())
} else {
return Err(format!(
"row has {} fields, but header had {}",
row.field_values.len(),
expected_field_count
));
}
}