Struct StaticSchemes

Source
pub struct StaticSchemes { /* private fields */ }
Expand description

A struct which contains all serialized static schemes. It also allows to serialize its content to file in order to embed the content to binary or to increase load speed and not to distribute sources.

Implementations§

Source§

impl StaticSchemes

Source

pub fn new() -> Self

Source

pub fn add(&mut self, ser_title: String, ser_scheme: Arc<Serializator>)

Source

pub fn merge(&mut self, other: Self)

Merges to self other instance.

Examples found in repository?
examples/common_search/common_search.rs (line 20)
9fn main()
10{
11    let curdir = std::env::current_dir().unwrap();
12
13    println!("{}", curdir.display());
14
15    // init parser instance
16    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
17
18    // read a static scheme which describes our data structures i.e files filters.shm and logsmon.shm
19    let mut res = schm.run_from_file("examples/common_search/filters.shm", None).unwrap();
20    res.merge(schm.run_from_file("examples/common_search/logsmon.shm", None).unwrap());
21
22    // get our serializator instance which was parsed from static file
23    let resser = res.get("filters").unwrap().clone();
24
25    // creating new `RustCode` instance where the data structs from serializator `filters` will be placed
26    let mut rc1 = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
27    resser.generate_rust_code(&mut rc1).unwrap();
28
29    // creating new `RustCode` instance where the data structs from serializator `logsmon` will be placed
30    let resser = res.get("logsmon").unwrap().clone();
31    let mut rc2 = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
32    resser.generate_rust_code(&mut rc2).unwrap();
33
34    println!("after removing commons");
35
36    // search for common structs/enums between RustCode instances for filter.shm and logsmon.shm
37    let t = std::time::Instant::now();
38    let com_res = RustCode::search_common("super::structs::struct_common", vec!(&mut rc1, &mut rc2), vec![RustCodeDerives::Debug], vec![], None);
39    let s = t.elapsed();
40    println!("time taken: {:?}", s);
41    println!("{}", rc1);
42
43    println!("{}", rc2);
44    
45    // if something was found, then it will be stored in inner type of Option
46    if com_res.is_some() == true
47    {
48        let com = com_res.unwrap();
49        
50        println!("Common structs: \n\n{}", com);
51
52        assert_eq!(com.contains("LdFilterSets"), true);
53    }
54}
Source

pub fn get<T>(&self, ser_title: T) -> Option<&Arc<Serializator>>
where T: AsRef<str>,

Examples found in repository?
examples/analyzer_error/test_err.rs (line 17)
6fn main()
7{
8    let curdir = std::env::current_dir().unwrap();
9
10    println!("{}", curdir.display());
11
12    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
13
14    let res = 
15        schm.run_from_file("examples/analyzer_error/schm_init.shm", None).unwrap();
16
17    let scheme = res.get("test_auto").unwrap();
18
19    let anres = scheme.analyze().unwrap();
20
21    println!("{}", anres);
22
23}
More examples
Hide additional examples
examples/error_descr_test/errtest.rs (line 17)
6fn main()
7{
8    let mut curdir = std::env::current_dir().unwrap();
9    curdir.push("examples/error_descr_test/incorr_schm.shm");
10    println!("{}", curdir.display());
11
12    let lex = Lexer::from_file(curdir).unwrap();
13    let schm = SchemeInit::new().unwrap();
14
15    let res = schm.run(&lex, None).unwrap();
16
17    let ser = res.get("errtest1").unwrap().clone();
18
19
20    let mut curdir = std::env::current_dir().unwrap();
21    curdir.push("examples/error_descr_test/incor_data.shm");
22
23    let (_dynenv, _dyn_res) = 
24        DynEnvironment::from_file(curdir, ser.clone()).unwrap();
25
26}
examples/test2.rs (line 33)
22fn main1() -> SchemeResult<()>
23{
24    let mut curdir = std::env::current_dir().unwrap();
25    curdir.push("examples/test1.shm");
26    println!("{}", curdir.display());
27
28    let lex = lexer::Lexer::from_file(curdir)?;
29    let schm = init::SchemeInit::new()?;
30
31    let res = schm.run(&lex, None)?;
32
33    let resser = res.get("test1").unwrap().clone();
34
35    println!("Static: \n{:?}\n", res);
36
37    let mut curdir = std::env::current_dir().unwrap();
38    curdir.push("examples/test2.shm");
39
40    let dynres = environment::DynEnvironment::from_file(curdir, resser);
41
42    println!("Dynamic: \n{:?}\n", dynres);
43
44
45    return Ok(());
46
47}
examples/define_test.rs (line 20)
6fn main()
7{
8    let mut curdir = std::env::current_dir().unwrap();
9    curdir.push("examples/defines_init.shm");
10
11    println!("{}", curdir.display());
12    
13    let lex = lexer::Lexer::from_file(curdir).unwrap();
14    let schm = init::SchemeInit::new().unwrap();
15
16    let res = schm.run(&lex, None).unwrap();
17
18    println!("{:?}", res);
19
20    let resser = res.get("defines").unwrap().clone();
21
22    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
23
24    println!("Structures: ");
25    match resser.generate_rust_code(&mut rc)
26    {
27        Ok(_) => 
28        {
29            println!("{}", rc);
30        },
31        Err(e) => 
32        {
33            println!("{}", e);
34        }
35    }
36}
examples/another/another.rs (line 19)
9fn main()
10{
11    let curdir = std::env::current_dir().unwrap();
12
13    println!("{}", curdir.display());
14
15    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
16
17    let res = schm.run_from_file("examples/another/init_l.shm", None).unwrap();
18
19    let resser = res.get("logsmon").unwrap().clone();
20
21    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
22    println!("Structures: ");
23    match resser.generate_rust_code(&mut rc)
24    {
25        Ok(_) => 
26        {
27            println!("{}", rc);
28        },
29        Err(e) => 
30        {
31            println!("{}", e);
32        }
33    }
34
35    let anres = resser.analyze().unwrap();
36
37    println!("errors:\n{}", anres);
38
39    let mut curdir = std::env::current_dir().unwrap();
40
41    curdir.push("examples/another/data_l.shm");
42
43    let (_, _dyn_res) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
44
45    let resser = res.get("logsmon").unwrap().clone();
46
47    let anres = resser.analyze().unwrap();
48
49    println!("errors:\n{}", anres);
50
51
52
53}
examples/struct_to_scheme/vector_arg/struct2scheme.rs (line 39)
28pub fn main()
29{
30    let mut curdir = std::env::current_dir().unwrap();
31    curdir.push("examples/struct_to_scheme/vector_arg/test_vec1.shm");
32    println!("{}", curdir.display());
33
34    let lex = lexer::Lexer::from_file(curdir).unwrap();
35    let schm = init::SchemeInit::new().unwrap();
36
37    let res = schm.run(&lex, None).unwrap();
38
39    let resser = res.get("test10").unwrap().clone();
40
41    println!("Static: \n{:?}\n", res);
42
43
44    let mut curdir = std::env::current_dir().unwrap();
45    curdir.push("examples/struct_to_scheme/vector_arg/test_vec1_data.shm");
46
47
48    let (_, dynres) = environment::DynEnvironment::from_file(&curdir, resser.clone()).unwrap();
49
50    let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
51
52    let serialized = serde_json::to_string(&ret).unwrap();
53
54
55    let n: CommonLevels = serde_json::from_str(&serialized).unwrap();
56
57    let resreser = from_struct(n, resser);
58    
59    if resreser.is_err() == true
60    {
61        panic!("{}", resreser.err().unwrap());
62    }
63    else
64    {
65        println!("{}", resreser.unwrap());
66    }
67}
Source

pub fn remove<T>(&mut self, ser_title: T) -> Option<(String, Arc<Serializator>)>
where T: AsRef<str>,

Source

pub fn deserialize_bin(data: &[u8]) -> Result<Self, Box<ErrorKind>>

Source

pub fn serialize_bin(&self) -> Result<Vec<u8>, Box<ErrorKind>>

Serializes its content to binary format.

Source

pub fn deserialize_json(data: &str) -> Result<Self, Error>

Source

pub fn serialize_json(&self) -> Result<String, Error>

Serializes its content to JSON format.

Source

pub fn into_iter(self) -> IntoIter<String, Arc<Serializator>>

Source

pub fn iter(&self) -> Iter<'_, String, Arc<Serializator>>

Source

pub fn schemes_count(&self) -> usize

Trait Implementations§

Source§

impl Clone for StaticSchemes

Source§

fn clone(&self) -> StaticSchemes

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StaticSchemes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for StaticSchemes

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for StaticSchemes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for StaticSchemes

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,