I've read some docs on serde.rs, watched the yesterday's video that's on its front page now, and read some crates sources to get just some understanding how it works on the side of formats (not structs).
And it still not clear. The example in the docs shows calls to from_str
, from_bytes
, etc.
So, question #1: is serde made to work only with streams of bytes or text? (I know it's not a parsing library.)
But what if I have a format driver, like flatgeobuf
(or GeoPackage), which gives me an iterator and fields accessors. Right now I process this with custom code, rewriting it each time for a struct and file:
struct MyStruct { field1: i32, field2: f64, geometry: Point }
for row in my_fgb_reader.iter()? {
let feature = row?;
let field1 = feature.read_field::<i32>("field1")?;
let field2 = feature.read_field::<f64>("field2")?;
let geometry = feature.read_geometry::<Point>()?;
do_something_with(MyStruct { field1, field2, geometry })?;
}
I'd love to have a tool to do this kind of thing:
#[derive(deserializer trait from some crate)]
struct MyStruct { field1: i32, field2: f64, geometry: Point }
for item in MyStruct::iter_from(my_fgb_reader) {
let obj:MyStruct = item?;
do_something_with(obj)?;
}
Question #2: Is this kind of thing doable with Serde, or any other crate?