pub struct Serialization {}
Implementations§
Source§impl Serialization
impl Serialization
Sourcepub fn serialize(
root_ser: Arc<Serializator>,
root_dp: Arc<DynProcedure>,
) -> SerializationRes<SerDynValue>
pub fn serialize( root_ser: Arc<Serializator>, root_dp: Arc<DynProcedure>, ) -> SerializationRes<SerDynValue>
Performs a serialization of the collected data from the config which is
stored in the DynProcedure. The returned result is prepared to be serialized
and deserialized into structures which can be generated by static_scheme/generator.rs
.
§Arguments
-
root_ser
- a Serializator structure which contains all necessary information about how the data should be serialized. -
root_dp
- contains data obtained from the config file in form of the DynProcedure.
§Returns
A SerializationRes is returned with:
-
Result::Ok is returned with SerDynValue as inner type.
-
Result::Err is returned with error description.
Examples found in repository?
examples/struct_to_scheme/vector_arg/struct2scheme.rs (line 49)
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 schm = init::SchemeInit::new_with_path("examples/struct_to_scheme/vector_arg").unwrap();
35
36 let res = schm.run_from_file("test_vec1.shm", None).unwrap();
37
38 let resser = res.get("test10").unwrap().clone();
39
40 println!("Static: \n{:?}\n", res);
41
42
43 let mut curdir = std::env::current_dir().unwrap();
44 curdir.push("examples/struct_to_scheme/vector_arg/test_vec1_data.shm");
45
46
47 let (_, dynres) = environment::DynEnvironment::from_file(&curdir, resser.clone()).unwrap();
48
49 let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
50
51 let serialized = serde_json::to_string(&ret).unwrap();
52
53
54 let n: CommonLevels = serde_json::from_str(&serialized).unwrap();
55
56 let resreser = from_struct(n, resser);
57
58 if resreser.is_err() == true
59 {
60 panic!("{}", resreser.err().unwrap());
61 }
62 else
63 {
64 println!("{}", resreser.unwrap());
65 }
66}
More examples
examples/test10.rs (line 39)
16pub fn main()
17{
18 let mut curdir = std::env::current_dir().unwrap();
19 curdir.push("examples/test4.shm");
20 println!("{}", curdir.display());
21
22 let lex = lexer::Lexer::from_file(curdir).unwrap();
23 let schm = init::SchemeInit::new().unwrap();
24
25 let res = schm.run(None, &lex, None).unwrap();
26
27 let resser = res.get("test10").unwrap().clone();
28
29 println!("Static: \n{:?}\n", res);
30
31 let mut curdir = std::env::current_dir().unwrap();
32 curdir.push("examples/test11.shm");
33
34
35 let (_, dynres) = environment::DynEnvironment::from_file(&curdir, resser.clone()).unwrap();
36
37 println!("Dynamic: \n{:?}\n", dynres);
38
39 let ret = serializator::Serialization::serialize(resser, dynres.clone()).unwrap();
40
41 let serialized = serde_json::to_string(&ret).unwrap();
42
43
44 let tr = CommonLevels{lvl_a: -2..8, lvl_b: 4..=5};
45
46 let res = serde_json::to_string(&tr).unwrap();
47
48 println!("control: {}", res);
49
50 let deser: CommonLevels = serde_json::from_str(&serialized).unwrap();
51
52 println!("{:?}", deser);
53
54 if deser != tr
55 {
56 println!("did not match!");
57 }
58}
examples/struct_to_scheme/enum_proc/struct2scheme.rs (line 44)
24pub fn main()
25{
26 let mut curdir = std::env::current_dir().unwrap();
27 curdir.push("examples/struct_to_scheme/enum_proc/init_use1.shm");
28 println!("{}", curdir.display());
29
30 let schm = init::SchemeInit::new_with_path("examples/struct_to_scheme/enum_proc").unwrap();
31
32 let res = schm.run_from_file("init_use1.shm", None).unwrap();
33
34 let resser = res.get("use1").unwrap().clone();
35
36 println!("Static: \n{:?}\n", res);
37
38
39 let mut curdir = std::env::current_dir().unwrap();
40 curdir.push("examples/struct_to_scheme/enum_proc/init_use_dyn1.shm");
41
42 let (_, dynres) = environment::DynEnvironment::from_file(&curdir, resser.clone()).unwrap();
43
44 let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
45
46 let serialized = serde_json::to_string(&ret).unwrap();
47
48
49 let n: TestUseEnum = serde_json::from_str(&serialized).unwrap();
50
51 let resser = from_struct(n, resser);
52
53 println!("result:");
54 if resser.is_err() == true
55 {
56 panic!("{}", resser.err().unwrap());
57 }
58 else
59 {
60 println!("{}", resser.unwrap());
61 }
62}
examples/complex_example_1/init_networking1.rs (line 32)
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_extensions/test_exts.rs (line 39)
15pub fn main()
16{
17 let mut curdir = std::env::current_dir().unwrap();
18 curdir.push("examples/scheme_extensions/test_exts.shm");
19 println!("{}", curdir.display());
20
21 let lex = lexer::Lexer::from_file(curdir).unwrap();
22 let schm = init::SchemeInit::new().unwrap();
23
24 let res = schm.run(None, &lex, None).unwrap();
25
26 let resser = res.get("test_exts").unwrap().clone();
27
28 println!("Static: \n{:?}\n", res);
29
30
31 let mut curdir = std::env::current_dir().unwrap();
32 curdir.push("examples/scheme_extensions/test_exts_data.shm");
33
34
35 let (_, dynres) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
36
37 println!("Dynamic: \n{:?}\n", dynres);
38
39 let ret = serializator::Serialization::serialize(resser, dynres.clone()).unwrap();
40
41 let serialized = serde_json::to_string(&ret).unwrap();
42
43
44 let tr = ExtTest{ var_name: "var1".to_string(), entity: "od".to_string(), title: "model123".to_string() };
45
46 let res = serde_json::to_string(&tr).unwrap();
47
48 println!("control: {}", res);
49
50 let deser: ExtTest = serde_json::from_str(&serialized).unwrap();
51
52 println!("{:?}", deser);
53
54 if deser != tr
55 {
56 panic!("did not match!");
57 }
58 else
59 {
60 println!("matched!");
61 }
62}
examples/struct_to_scheme3/struct2scheme3.rs (line 202)
183pub fn main()
184{
185
186// static
187 let mut curdir = std::env::current_dir().unwrap();
188 curdir.push("examples/struct_to_scheme3");
189 println!("{}", curdir.display());
190
191 let schm = init::SchemeInit::new_with_path(curdir).unwrap();
192 let res = schm.run_from_file("filters.shm", None).unwrap();
193 let resser = res.get("filters").unwrap().clone();
194
195// dynamic
196 let mut curdir = std::env::current_dir().unwrap();
197 curdir.push("examples/struct_to_scheme3/nginx.shm");
198 let (_, dynres) =
199 environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
200
201// serialize dyn
202 let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
203
204 let serialized = serde_json::to_string(&ret).unwrap();
205
206/*
207 let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
208 println!("Structures: ");
209 match resser.generate_rust_structs(&mut rc)
210 {
211 Ok(_) =>
212 {
213 println!("{}", rc);
214 },
215 Err(e) =>
216 {
217 println!("{}", e);
218 }
219 }
220*/
221
222 let n: LdFilter = serde_json::from_str(&serialized).unwrap();
223
224 let resser = from_struct(n, resser);
225
226 if resser.is_err() == true
227 {
228 panic!("{}", resser.err().unwrap());
229 }
230 else
231 {
232 println!("{}", resser.unwrap());
233 }
234}
Additional examples can be found in:
- examples/struct_to_scheme/advanced2/struct2scheme.rs
- examples/enum_arg/enum_arg.rs
- examples/struct_to_scheme/advanced_arg/struct2scheme.rs
- examples/struct_to_scheme/struct_proc/struct2scheme.rs
- examples/scheme_vector/test_vec1.rs
- examples/scheme_enum/enumtest.rs
- examples/scheme_proc_enum/init_use1.rs
- examples/struct_to_scheme/advanced4/struct2scheme.rs
- examples/test3.rs
- examples/scheme_use/use_test.rs
- examples/scheme_longint/test_longint.rs
- examples/scheme_vector_proc/vector_proc.rs
- examples/scheme_auto/test_auto.rs
- examples/scheme_common_struct/test_com.rs
Auto Trait Implementations§
impl Freeze for Serialization
impl RefUnwindSafe for Serialization
impl Send for Serialization
impl Sync for Serialization
impl Unpin for Serialization
impl UnwindSafe for Serialization
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more