Function count

Source
pub fn count<'a, T>(f: String) -> Result<i32>
where T: DeserializeOwned + Debug + Clone + Send + Serialize + 'static,
Expand description

Count the contents of a json file.

§Arguments

  • f Filename and full accesislbe path of the input json file

§Return

  • count No of records that match the filter.

§Input types

  • T The type of the structure.

§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::count_with_filter::<
    TestSimple,
   Box<dyn Fn(TestSimple) -> bool>,
>("data/test_simple.json".to_string(), Box::new(filter));