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
impl Serializator
Sourcepub const SERIALIZATOR_FROM_MEMORY_PATH: &'static str = "from memory"
pub const SERIALIZATOR_FROM_MEMORY_PATH: &'static str = "from memory"
Returned instead of path when path is None
Sourcepub fn new(name: String) -> Self
pub fn new(name: String) -> Self
Creates new instance of serializator and sets the name
provided in the scheme.
Sourcepub fn set_file_path(&mut self, file_path: Option<PathBuf>)
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.
Sourcepub fn get_file_path(&self) -> Option<&PathBuf>
pub fn get_file_path(&self) -> Option<&PathBuf>
Sourcepub fn get_file_path_string_safe(&self) -> String
pub fn get_file_path_string_safe(&self) -> String
Returns a path or constant SERIALIZATOR_FROM_MEMORY_PATH if it was generated from memory.
Sourcepub fn get_defines_by_proc_dt(
&self,
proc_name: &String,
arg_dt: ArgDataType,
) -> Vec<Arc<Define>>
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
Sourcepub fn resolve_path_to_struct(
&self,
source: Arc<Procedure>,
path_to_label: &[String],
full_path_to_lbl: &[String],
) -> StaticSchemeRes<(Arc<Structure>, Arc<Procedure>)>
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 argumentpath_to_label
is resolved. -
path_to_label
- a path (by labels) to the target.
§Returns
Returns a [SchemeResult] where:
-
On success returns Result::Ok with reference to Structure and [Rc] to Procedure
-
On error, returns Result::Err with error description.
Sourcepub fn resolve_path_to_proc(
&self,
source: Arc<Procedure>,
path_to_label: &[String],
full_path_to_lbl: &[String],
) -> StaticSchemeRes<(Option<Arc<Structure>>, Arc<Procedure>)>
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>)>
Sourcepub fn resolve_path_to_enum(
&self,
source: Arc<Procedure>,
path_to_label: &[String],
full_path_to_lbl: &[String],
) -> StaticSchemeRes<(Arc<Enumerator>, Arc<Procedure>)>
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 argumentpath_to_label
is resolved. -
path_to_label
- a path (by labels) to the target.
§Returns
Returns a [SchemeResult] where:
-
On success returns Result::Ok with reference to Enumerator and [Rc] to Procedure
-
On error, returns Result::Err with error description.
Sourcepub fn resolve_path_to_arg(
&self,
source: Arc<Procedure>,
path_to_label: &[String],
full_path_to_lbl: &[String],
) -> StaticSchemeRes<Arc<Argument>>
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 argumentpath_to_label
is resolved. -
path_to_label
- a path (by labels) to the target.
§Returns
Returns a [SchemeResult] where:
-
On success returns Result::Ok with reference to [Rc] Argument
-
On error, returns Result::Err with error description.
Sourcepub fn generate_rust_code(
&self,
rust_code: &mut RustCode,
) -> StaticSchemeRes<()>
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.
-
Result::Ok - if operation is successful.
-
Result::Err - if operation has failed and error is returned.
Examples found in repository?
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
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}
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}
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}
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}
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}
Sourcepub fn generate_field_data_type(
&self,
rust_code: &mut RustCode,
field: &FieldDecl,
cur_proc_int: Arc<Procedure>,
cur_enumer: Option<Arc<Enumerator>>,
) -> StaticSchemeRes<RustCodeItemDataType>
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.
-
Result::Ok with the RustCodeItemDataType as inner type which contains a field data type information.
-
Result::Err with error description.
Sourcepub fn clone_name(&self) -> Arc<String>
pub fn clone_name(&self) -> Arc<String>
Clones a title of the serializer.
Sourcepub fn new_root_proc(&mut self, proc: Procedure) -> StaticSchemeRes<()>
pub fn new_root_proc(&mut self, proc: Procedure) -> StaticSchemeRes<()>
Declares new procedure
Sourcepub fn new_proc(&mut self, proc: Procedure) -> StaticSchemeRes<()>
pub fn new_proc(&mut self, proc: Procedure) -> StaticSchemeRes<()>
Declares new procedure.
Sourcepub fn symbol_define(&mut self, def: Define) -> StaticSchemeRes<()>
pub fn symbol_define(&mut self, def: Define) -> StaticSchemeRes<()>
Declares symbol.
pub fn symbol_enum_define(&mut self, def: DefineEnum) -> StaticSchemeRes<()>
Sourcepub fn set_root_serialization_struct(
&mut self,
ser: Structure,
) -> StaticSchemeRes<()>
pub fn set_root_serialization_struct( &mut self, ser: Structure, ) -> StaticSchemeRes<()>
Sets the root serialization descriptor.
Sourcepub fn add_serialization_struct(&mut self, ser: Structure)
pub fn add_serialization_struct(&mut self, ser: Structure)
Declares serialization information for structure.
Sourcepub fn add_serialization_enum(&mut self, enm: Enumerator)
pub fn add_serialization_enum(&mut self, enm: Enumerator)
Declares a serialization information for enum.
Sourcepub fn get_serialization_struct_by_procname(
&self,
proc_name: &String,
) -> StaticSchemeRes<Arc<Structure>>
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.
-
Result::Ok with reference to Structure is returned on success.
-
Result::Err with error description is returned.
pub fn get_serialization_struct_by_procname_opt( &self, proc_name: &String, ) -> Option<Arc<Structure>>
pub fn get_serialization_struct_by_name( &self, struct_name: &str, ) -> StaticSchemeRes<Arc<Structure>>
Sourcepub fn get_serialization_enum_by_procname(
&self,
proc_name: &String,
) -> SerializationPartialRes<&Enumerator>
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:
-
Result::Ok on success with the reference to Enumerator
-
Result::Err on error with the error description
pub fn get_procedure_by_name( &self, proc_name: &String, ) -> Option<&Arc<Procedure>>
Sourcepub fn get_root_ser(&self) -> Option<Arc<Structure>>
pub fn get_root_ser(&self) -> Option<Arc<Structure>>
Returns root serialization structure if was defined
Sourcepub fn get_root_proc(&self) -> Option<Arc<Procedure>>
pub fn get_root_proc(&self) -> Option<Arc<Procedure>>
Returns root procedure.
The [Rc] inside Option is cloned.
Sourcepub fn get_define_list_iter(&self) -> Iter<'_, Arc<String>, Arc<Define>>
pub fn get_define_list_iter(&self) -> Iter<'_, Arc<String>, Arc<Define>>
Returns iterator to defined symbols.
Sourcepub fn get_enum_define_list_iter(
&self,
) -> Iter<'_, Arc<String>, Arc<DefineEnum>>
pub fn get_enum_define_list_iter( &self, ) -> Iter<'_, Arc<String>, Arc<DefineEnum>>
Returns iterator to defined enum symbols.
pub fn get_enum_define_value_by_key( &self, key: &String, ) -> Option<&Arc<DefineEnum>>
Source§impl Serializator
impl Serializator
Sourcepub fn analyze(&self) -> SerializationPartialRes<AnalyzerErrors>
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.
-
Result::Ok with instance AnalyzerErrors is returned. This instance contains all found problems.
-
Result::Err is returned if fatal error happens.
Examples found in repository?
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
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}
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.
impl Clone for Serializator
A dummy clone. This instance must never be clonned.
Source§impl Debug for Serializator
impl Debug for Serializator
Source§impl<'de> Deserialize<'de> for Serializator
impl<'de> Deserialize<'de> for Serializator
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Serializator
impl Display for Serializator
Source§impl Serialize for Serializator
impl Serialize for Serializator
Source§impl<'nr> StaticProcedureParser<'nr> for Serializator
impl<'nr> StaticProcedureParser<'nr> for Serializator
Source§type RetType = Serializator
type RetType = Serializator
parse
function.Source§type RetTypeArg = Serializator
type RetTypeArg = Serializator
Source§type RetTypeInt = Serializator
type RetTypeInt = Serializator
parse_internal
function.