Add "Map" type to FileHeaderSpec and FileHeaderData
This commit is contained in:
parent
52e44e9d77
commit
1c2c52fa37
1 changed files with 17 additions and 0 deletions
|
@ -11,6 +11,7 @@ pub enum FileHeaderSpec {
|
||||||
Float,
|
Float,
|
||||||
Text,
|
Text,
|
||||||
Key { name: String, value_type: Box<FileHeaderSpec> },
|
Key { name: String, value_type: Box<FileHeaderSpec> },
|
||||||
|
Map { keys: Vec<FileHeaderSpec> },
|
||||||
Array { allowed_types: Box<Vec<FileHeaderSpec>> },
|
Array { allowed_types: Box<Vec<FileHeaderSpec>> },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ pub enum FileHeaderData {
|
||||||
Float(f64),
|
Float(f64),
|
||||||
Text(String),
|
Text(String),
|
||||||
Key { name: String, value: Box<FileHeaderData> },
|
Key { name: String, value: Box<FileHeaderData> },
|
||||||
|
Map { keys: Vec<FileHeaderData> },
|
||||||
Array { values: Box<Vec<FileHeaderData>> },
|
Array { values: Box<Vec<FileHeaderData>> },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +46,9 @@ impl Display for FileHeaderSpec {
|
||||||
&FileHeaderSpec::Key{name: ref n, value_type: ref vt} => {
|
&FileHeaderSpec::Key{name: ref n, value_type: ref vt} => {
|
||||||
write!(fmt, "Key({:?}) -> {:?}", n, vt)
|
write!(fmt, "Key({:?}) -> {:?}", n, vt)
|
||||||
}
|
}
|
||||||
|
&FileHeaderSpec::Map{keys: ref ks} => {
|
||||||
|
write!(fmt, "Map -> {:?}", ks)
|
||||||
|
}
|
||||||
&FileHeaderSpec::Array{allowed_types: ref at} => {
|
&FileHeaderSpec::Array{allowed_types: ref at} => {
|
||||||
write!(fmt, "Array({:?})", at)
|
write!(fmt, "Array({:?})", at)
|
||||||
}
|
}
|
||||||
|
@ -127,6 +132,18 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData)
|
||||||
return match_header_spec(&*vtype, &*val);
|
return match_header_spec(&*vtype, &*val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
&FileHeaderSpec::Map{keys: ref sks},
|
||||||
|
&FileHeaderData::Map{keys: ref dks}
|
||||||
|
) => {
|
||||||
|
for (s, d) in sks.iter().zip(dks.iter()) {
|
||||||
|
let res = match_header_spec(s, d);
|
||||||
|
if res.is_some() {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
&FileHeaderSpec::Array{allowed_types: ref vtypes},
|
&FileHeaderSpec::Array{allowed_types: ref vtypes},
|
||||||
&FileHeaderData::Array{values: ref vs}
|
&FileHeaderData::Array{values: ref vs}
|
||||||
|
|
Loading…
Reference in a new issue