Struct Serializator

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

This struct contains information about the Serializator instance which is defined in scheme and starting with (serialization “name” …).

Implementations§

Source§

impl Serializator

Source

pub const SERIALIZATOR_FROM_MEMORY_PATH: &'static str = "from memory"

Returned instead of path when path is None

Source

pub fn new(name: String) -> Self

Creates new instance of serializator and sets the name provided in the scheme.

Source

pub fn set_file_path(&mut self, file_path: Option<PathBuf>)

Sets to the created instance a path to the file which was used to generate current instance.

Source

pub fn get_file_path(&self) -> Option<&PathBuf>

Returns a reference to PathBuf inside Option. It contains the path to the file which was used to build the instance.

Source

pub fn get_file_path_string_safe(&self) -> String

Returns a path or constant SERIALIZATOR_FROM_MEMORY_PATH if it was generated from memory.

Source

pub fn get_defines_by_proc_dt( &self, proc_name: &String, arg_dt: ArgDataType, ) -> Vec<Arc<Define>>

Returns a list of references to the Define instance by the defined parameters.

The Define instance is defined to be used in proc_name procedure and contain data with the exact arg_dt data type.

§Arguments
  • proc_name - a name of the procedure.

  • arg_dt - a ArgDataType data type.

§Return

A Vec of Rc items is returned.

Source

pub fn resolve_path_to_struct( &self, source: Arc<Procedure>, path_to_label: &[String], full_path_to_lbl: &[String], ) -> StaticSchemeRes<(Arc<Structure>, Arc<Procedure>)>

Searches for a Structure (and Procedure) from the point specified by argument source which is Procedure.

This function is recursive!

§Arguments
  • source - a point from where the item from argument path_to_label is resolved.

  • path_to_label - a path (by labels) to the target.

§Returns

Returns a [SchemeResult] where:

Source

pub fn resolve_path_to_proc( &self, source: Arc<Procedure>, path_to_label: &[String], full_path_to_lbl: &[String], ) -> StaticSchemeRes<(Option<Arc<Structure>>, Arc<Procedure>)>

Searches for the Procedure instance. A starting point is source. A path is full_path_to_lbl. path_to_label is a recursivly modified list from where on each recursion an item is removed.

§Returns

An optional reference to Structure is returned in case if procedure is defined with structure.

Source

pub fn resolve_path_to_enum( &self, source: Arc<Procedure>, path_to_label: &[String], full_path_to_lbl: &[String], ) -> StaticSchemeRes<(Arc<Enumerator>, Arc<Procedure>)>

Searches for a Enumerator (and Procedure) from the point specified by argument source which is Procedure.

This function is recursive!

§Arguments
  • source - a point from where the item from argument path_to_label is resolved.

  • path_to_label - a path (by labels) to the target.

§Returns

Returns a [SchemeResult] where:

Source

pub fn resolve_path_to_arg( &self, source: Arc<Procedure>, path_to_label: &[String], full_path_to_lbl: &[String], ) -> StaticSchemeRes<Arc<Argument>>

Searches for a Argument from the point specified by argument source which is Procedure.

This function is recursive!

§Arguments
  • source - a point from where the item from argument path_to_label is resolved.

  • path_to_label - a path (by labels) to the target.

§Returns

Returns a [SchemeResult] where:

Source

pub fn generate_rust_code( &self, rust_code: &mut RustCode, ) -> StaticSchemeRes<()>

Generates a Rust code (structures and enums) from the root of the document.

§Arguments
  • rust_code - a mutable reference to RustCode instance which is used to collect result.
§Returns

A [SchemeResult] is returned.

Examples found in repository?
examples/define_test.rs (line 25)
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}
More examples
Hide additional examples
examples/another/another.rs (line 23)
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/complex_example_1/init_networking1.rs (line 41)
10fn main()
11{
12    let curdir = std::env::current_dir().unwrap();
13
14    println!("{}", curdir.display());
15
16    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
17
18    let res = schm.run_from_file("examples/complex_example_1/init_networking.shm", None).unwrap();
19
20    let resser = res.get("networking").unwrap().clone();
21
22    let anres = resser.analyze().unwrap();
23
24    println!("errors:\n{}", anres);
25
26    let mut curdir = std::env::current_dir().unwrap();
27
28    curdir.push("examples/complex_example_1/init_networking_dyn1.shm");
29
30    let (_, dyn_res) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
31
32    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
33
34    let serialized = serde_json::to_string(&ret).unwrap();
35
36    println!("Result:\n{}", serialized);
37
38    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
39
40    println!("Structures: ");
41    match resser.generate_rust_code(&mut rc)
42    {
43        Ok(_) => 
44        {
45            println!("{}", rc);
46        },
47        Err(e) => 
48        {
49            println!("{}", e);
50        }
51    }
52
53}
examples/scheme_enum/enumtest.rs (line 56)
39fn main()
40{
41    let curdir = std::env::current_dir().unwrap();
42    //curdir.push("examples/test3.shm");
43    println!("{}", curdir.display());
44   // let lex = lexer::Lexer::from_file(curdir).unwrap();
45    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
46
47    let res = schm.run_from_file("examples/scheme_enum/init_enum.shm", None).unwrap();
48
49    let resser = res.get("test1").unwrap().clone();
50
51    println!("{:?}", res);
52
53    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
54
55    println!("Structures: ");
56    match resser.generate_rust_code(&mut rc)
57    {
58        Ok(_) => 
59        {
60            println!("{}", rc);
61        },
62        Err(e) => 
63        {
64            panic!("{}", e);
65        }
66    }
67
68    let mut curdir = std::env::current_dir().unwrap();
69    curdir.push("examples/scheme_enum/enum.shm");
70
71    let (_, dyn_res) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
72
73    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
74
75    //println!("dynproc:\n{:?}\n", dyn_res);
76
77    let serialized = serde_json::to_string(&ret).unwrap();
78
79    println!("Result:\n{}", serialized);
80
81    let _deserialized: CommonLevels = serde_json::from_str(&serialized).unwrap();
82
83    let lvls = 
84        CommonLevels
85        {
86            enum1: MyEnum::Item1,
87            enum2: OurEnum::Item2,
88            enum3: MyEnum::Item2,
89            enum4: vec![OurEnum::HItem1, OurEnum::Item2, OurEnum::CItem],
90        };
91
92    let serialized_nat = serde_json::to_string(&lvls).unwrap();
93
94    println!("nat:{}", serialized_nat);
95    println!("ser:{}", serialized);
96
97    if serialized != serialized_nat
98    {
99        panic!("not equal");
100    }
101
102
103}
examples/scheme_proc_enum/init_use1.rs (line 72)
20fn main()
21{
22    let curdir = std::env::current_dir().unwrap();
23
24    println!("{}", curdir.display());
25
26    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
27
28    let res = schm.run_from_file("examples/scheme_proc_enum/init_use1.shm", None).unwrap();
29
30    let resser = res.get("use1").unwrap().clone();
31
32    let mut curdir = std::env::current_dir().unwrap();
33
34    curdir.push("examples/scheme_proc_enum/init_use_dyn1.shm");
35
36   // let lex = lexer::Lexer::from_file(curdir).unwrap();
37    let (_dynenv, dyn_res) = 
38        environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
39   // let dynenv = environment::DynEnvironment::new_root(resser.clone());
40
41    //let dyn_res = environment::DynEnvironment::run(&lex, dynenv).unwrap();
42
43    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
44
45    let serialized = serde_json::to_string(&ret).unwrap();
46
47    println!("Result:\n{}", serialized);
48    let local_inst = 
49        TestUseEnum::ColorRgbaProfile
50        {
51            profile_name: "profile1".to_string(),
52            col_r: 6,
53            col_g: 5,
54            col_b: 64,
55            col_a: 100
56        };
57
58    let local_inst_ser = serde_json::to_string(&local_inst).unwrap();
59
60    assert_eq!(local_inst_ser.as_str(), serialized.as_str());
61
62
63    
64
65    let deserialized: TestUseEnum = serde_json::from_str(&serialized).unwrap();
66
67    println!("Deserialized result: \n{:?}", deserialized);
68
69    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
70
71    println!("Structures: ");
72    match resser.generate_rust_code(&mut rc)
73    {
74        Ok(_) => 
75        {
76            println!("{}", rc);
77        },
78        Err(e) => 
79        {
80            panic!("{}", e);
81        }
82    }
83
84}
examples/test3.rs (line 90)
32fn main()
33{
34    let curdir = std::env::current_dir().unwrap();
35    //curdir.push("examples/test3.shm");
36    println!("{}", curdir.display());
37   // let lex = lexer::Lexer::from_file(curdir).unwrap();
38    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
39
40    let res = schm.run_from_file("examples/test3.shm", None).unwrap();
41
42    println!("{:?}", res);
43
44    let resser = res.get("test1").unwrap().clone();
45
46
47
48    let mut curdir = std::env::current_dir().unwrap();
49    curdir.push("examples/test2.shm");
50
51
52    let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap();
53
54    let dyn_res = environment::DynEnvironment::run_from_file(curdir, dynenv).unwrap();
55
56    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
57
58    //println!("dynproc:\n{:?}\n", dyn_res);
59
60    let serialized = serde_json::to_string(&ret).unwrap();
61
62    println!("Result:\n{}", serialized);
63
64    let _deserialized: CommonLevels = serde_json::from_str(&serialized).unwrap();
65
66    let lvls = 
67        Levels
68        {
69            name: "testing1234".to_string(),
70            ch_a: Some(100),
71            ch_b: 2,
72            g_type: vec![GeomType::Line(4, 6, 5), GeomType::Ray{l: 56, w: 44}, GeomType::Test],
73        };
74
75    let cl = CommonLevels{lvl: lvls};
76
77    let serialized_nat = serde_json::to_string(&cl).unwrap();
78
79    println!("nat:{}", serialized_nat);
80    println!("ser:{}", serialized);
81
82    if serialized != serialized_nat
83    {
84        println!("not equal");
85    }
86
87    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
88
89    println!("Structures: ");
90    match resser.generate_rust_code(&mut rc)
91    {
92        Ok(_) => 
93        {
94            println!("{}", rc);
95        },
96        Err(e) => 
97        {
98            println!("{}", e);
99        }
100    }
101}
Source

pub fn generate_field_data_type( &self, rust_code: &mut RustCode, field: &FieldDecl, cur_proc_int: Arc<Procedure>, cur_enumer: Option<Arc<Enumerator>>, ) -> StaticSchemeRes<RustCodeItemDataType>

Generates a field’s (Rust) datatype.

§Arguments
  • rust_code - a mutable reference to RustCode instance which is used to build code.

  • field - a reference to FieldDecl with the field description from serialization information.

  • cur_proc_int - a related Procedure to the serialized data.

§Returns

A [SchemeResult] is returned.

Source

pub fn get_name(&self) -> &String

Returns a title of the serializer.

Source

pub fn clone_name(&self) -> Arc<String>

Clones a title of the serializer.

Source

pub fn new_root_proc(&mut self, proc: Procedure) -> StaticSchemeRes<()>

Declares new procedure

Source

pub fn new_proc(&mut self, proc: Procedure) -> StaticSchemeRes<()>

Declares new procedure.

Source

pub fn symbol_define(&mut self, def: Define) -> StaticSchemeRes<()>

Declares symbol.

Source

pub fn symbol_enum_define(&mut self, def: DefineEnum) -> StaticSchemeRes<()>

Source

pub fn set_root_serialization_struct( &mut self, ser: Structure, ) -> StaticSchemeRes<()>

Sets the root serialization descriptor.

Source

pub fn add_serialization_struct(&mut self, ser: Structure)

Declares serialization information for structure.

Source

pub fn add_serialization_enum(&mut self, enm: Enumerator)

Declares a serialization information for enum.

Source

pub fn get_serialization_struct_by_procname( &self, proc_name: &String, ) -> StaticSchemeRes<Arc<Structure>>

Searches for the Structure by the proc_name which is a procedure name.

§Arguments
  • proc_name - a reference to String which contains title of the procedure.
§Returns

A [SchemeResult] with result is returned.

Source

pub fn get_serialization_struct_by_procname_opt( &self, proc_name: &String, ) -> Option<Arc<Structure>>

Source

pub fn get_serialization_struct_by_name( &self, struct_name: &str, ) -> StaticSchemeRes<Arc<Structure>>

Source

pub fn get_serialization_enum_by_procname( &self, proc_name: &String, ) -> SerializationPartialRes<&Enumerator>

Searches for the Enumerator serialization information for enum by the procedure name which enumerator instance is serializing.

§Arguments
  • proc_name - a reference to String which points to procedure name.
§Returns

A [SchemeResult] is returned with:

Source

pub fn get_procedure_by_name( &self, proc_name: &String, ) -> Option<&Arc<Procedure>>

Source

pub fn get_root_ser(&self) -> Option<Arc<Structure>>

Returns root serialization structure if was defined

Source

pub fn get_root_proc(&self) -> Option<Arc<Procedure>>

Returns root procedure.

The [Rc] inside Option is cloned.

Source

pub fn get_define_list_iter(&self) -> Iter<'_, Arc<String>, Arc<Define>>

Returns iterator to defined symbols.

Source

pub fn get_enum_define_list_iter( &self, ) -> Iter<'_, Arc<String>, Arc<DefineEnum>>

Returns iterator to defined enum symbols.

Source

pub fn get_enum_define_value_by_key( &self, key: &String, ) -> Option<&Arc<DefineEnum>>

Source

pub fn get_procedure_list_iter(&self) -> Iter<'_, Arc<String>, Arc<Procedure>>

Returns iterator to all defined procedures.

Source§

impl Serializator

Source

pub fn analyze(&self) -> SerializationPartialRes<AnalyzerErrors>

Performs analysis of static scheme. At the moment it is able to find unused procedures and arguments.

§Returns

Function returns Result as SerializationPartialRes.

Examples found in repository?
examples/analyzer_error/test_err.rs (line 19)
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/another/another.rs (line 35)
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/complex_example_1/init_networking1.rs (line 22)
10fn main()
11{
12    let curdir = std::env::current_dir().unwrap();
13
14    println!("{}", curdir.display());
15
16    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
17
18    let res = schm.run_from_file("examples/complex_example_1/init_networking.shm", None).unwrap();
19
20    let resser = res.get("networking").unwrap().clone();
21
22    let anres = resser.analyze().unwrap();
23
24    println!("errors:\n{}", anres);
25
26    let mut curdir = std::env::current_dir().unwrap();
27
28    curdir.push("examples/complex_example_1/init_networking_dyn1.shm");
29
30    let (_, dyn_res) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
31
32    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
33
34    let serialized = serde_json::to_string(&ret).unwrap();
35
36    println!("Result:\n{}", serialized);
37
38    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
39
40    println!("Structures: ");
41    match resser.generate_rust_code(&mut rc)
42    {
43        Ok(_) => 
44        {
45            println!("{}", rc);
46        },
47        Err(e) => 
48        {
49            println!("{}", e);
50        }
51    }
52
53}

Trait Implementations§

Source§

impl Clone for Serializator

A dummy clone. This instance must never be clonned.

Source§

fn clone(&self) -> Self

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 Serializator

Source§

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

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

impl<'de> Deserialize<'de> for Serializator

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 Serializator

Source§

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

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

impl Serialize for Serializator

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
Source§

impl<'nr> StaticProcedureParser<'nr> for Serializator

Source§

type RetType = Serializator

A return type for the parse function.
Source§

type RetTypeArg = Serializator

An argument for the helper function.
Source§

type RetTypeInt = Serializator

A return type for the parse_internal function.
Source§

fn parse_internal( si: &'nr SchemeInit<'nr>, nodes: NodesReader<'nr>, serializ: Self::RetTypeArg, ) -> StaticSchemeRes<Self::RetTypeInt>

An additional function for the recursion.
Source§

fn parse( si: &'nr SchemeInit<'nr>, nodes: NodesReader<'nr>, ) -> StaticSchemeRes<Self::RetType>

A main entry function. 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>,