pub fn filter<'a, T, F>(f: String, filter: F, o: String) -> Result<ReturnValues>Expand description
Filter the contents of a json file with filter specified and write the output to file specified.
§Arguments
fFilename and full accesislbe path of the input json filefilterA closure that can handle an input parameter of type T.oFilename and full accesislbe path of the output json file.
§Input types
TThe type of the structure.FClosure template with input function type.
§Example usage
use mmap_json_file;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
struct TestSimple {
a: Option<String>,
c: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
struct TestSimpleNested {
b: Option<TestSimple>,
c: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
struct TestSimpleCompound {
a: Option<TestSimpleNested>,
f: Option<String>,
}
let filter = |record: TestSimple| -> bool { record.a.unwrap() == "b" };
let _res = mmap_json_file::filter::<TestSimple, Box<dyn Fn(TestSimple) -> bool>>(
"data/test_simple.json".to_string(),
Box::new(filter),
"output.json".to_string(),
);