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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// An example how to seach common structs/enums and to store found data structures 
// in a separate file to avoid duplicates.

use shm_rs::static_scheme::generator::RustCode;
use shm_rs::static_scheme::init;


fn main()
{
    let curdir = std::env::current_dir().unwrap();

    println!("{}", curdir.display());

    // init parser instance
    let schm = init::SchemeInit::new_with_path(curdir).unwrap();

    // read a static scheme which describes our data structures i.e files filters.shm and logsmon.shm
    let mut res = schm.run_from_file("examples/common_search/filters.shm", None).unwrap();
    res.merge(schm.run_from_file("examples/common_search/logsmon.shm", None).unwrap());

    // get our serializator instance which was parsed from static file
    let resser = res.get("filters").unwrap().clone();

    // creating new `RustCode` instance where the data structs from serializator `filters` will be placed
    let mut rc1 = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
    resser.generate_rust_structs(&mut rc1).unwrap();

    // creating new `RustCode` instance where the data structs from serializator `logsmon` will be placed
    let resser = res.get("logsmon").unwrap().clone();
    let mut rc2 = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
    resser.generate_rust_structs(&mut rc2).unwrap();

    println!("after removing commons");

    // search for common structs/enums between RustCode instances for filter.shm and logsmon.shm
    let t = std::time::Instant::now();
    let com_res = RustCode::search_common("super::structs::struct_common", vec!(&mut rc1, &mut rc2), &["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
    let s = t.elapsed();
    println!("time taken: {:?}", s);
    println!("{}", rc1);

    println!("{}", rc2);
    
    // if something was found, then it will be stored in inner type of Option
    if com_res.is_some() == true
    {
        println!("Common structs: \n\n{}", com_res.unwrap());
    }
}