Struct DynEnvironment

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

A formed dynamic emvironment which is composed from the static scheme files which describes how to read the config file.

Implementations§

Source§

impl DynEnvironment

Source

pub fn new_root(scheme: Arc<Serializator>) -> DynSchmRes<Arc<Self>>

Creates new root and returning instance or error description.

Examples found in repository?
examples/enum_arg/enum_arg.rs (line 78)
37pub fn main()
38{
39    let mut curdir = std::env::current_dir().unwrap(); 
40    curdir.push("examples/struct_to_scheme/enum_arg/init_enum.shm");
41    println!("{}", curdir.display());
42
43    let schm = init::SchemeInit::new_with_path("examples/enum_arg").unwrap();
44
45    let res = schm.run_from_file("init_enum.shm", None).unwrap();
46
47    let resser = res.get("test1").unwrap().clone();
48
49    println!("Static: \n{:?}\n", res);
50
51
52    let mut curdir = std::env::current_dir().unwrap();
53    curdir.push("examples/enum_arg/enum.shm");
54
55
56    let (_, dynres) = environment::DynEnvironment::from_file(&curdir, resser.clone()).unwrap();
57
58    let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
59
60    let serialized = serde_json::to_string(&ret).unwrap();
61
62
63    let n: CommonLevels = serde_json::from_str(&serialized).unwrap();
64
65    let scmp = from_struct(n, resser.clone());
66    
67    if scmp.is_err() == true
68    {
69        panic!("{}", scmp.err().unwrap());
70    }
71    else
72    {
73        let out_res = scmp.unwrap();
74        println!("{}", out_res);
75
76        let lex_out = Lexer::from_str(&out_res.to_string(), "test").unwrap();
77
78        let dyn_root = environment::DynEnvironment::new_root(resser.clone()).unwrap();
79
80        let dyn_res =
81            environment::DynEnvironment::run(lex_out, dyn_root);
82
83        if dyn_res.is_err() == true
84        {
85            println!("{}", dyn_res.err().unwrap());
86        }
87    }
88}
More examples
Hide additional examples
examples/struct_to_scheme/advanced4/struct2scheme.rs (line 254)
199pub fn main()
200{
201
202// static
203    let mut curdir = std::env::current_dir().unwrap();
204    curdir.push("examples/struct_to_scheme/advanced4");
205    println!("{}", curdir.display());
206
207    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
208    let res = schm.run_from_file("init_logdaemon.shm", None).unwrap();
209    let resser = res.get("logdaemon").unwrap().clone();
210
211// dynamic
212    let mut curdir = std::env::current_dir().unwrap();
213    curdir.push("examples/struct_to_scheme/advanced4/logdaemon.shm");
214    let (_, dynres) = 
215        environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
216
217// serialize dyn
218    let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
219
220    let serialized = serde_json::to_string(&ret).unwrap();
221
222/*
223    let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
224    println!("Structures: ");
225    match resser.generate_rust_structs(&mut rc)
226    {
227        Ok(_) => 
228        {
229            println!("{}", rc);
230        },
231        Err(e) => 
232        {
233            println!("{}", e);
234        }
235    }
236*/
237
238
239    let n: LdLogDaemon = serde_json::from_str(&serialized).unwrap();
240
241    let scmp = from_struct(n, resser.clone());
242    
243    if scmp.is_err() == true
244    {
245        panic!("{}", scmp.err().unwrap());
246    }
247    else
248    {
249        let out_res = scmp.unwrap();
250        println!("{}", out_res);
251
252        let lex_out = Lexer::from_str(&out_res.to_string(), "test").unwrap();
253
254        let dyn_root = environment::DynEnvironment::new_root(resser.clone()).unwrap();
255
256        let dyn_res =
257            environment::DynEnvironment::run(lex_out, dyn_root);
258
259        if dyn_res.is_err() == true
260        {
261            println!("{}", dyn_res.err().unwrap());
262        }
263
264
265    }
266    
267}
examples/test3.rs (line 53)
33fn main()
34{
35    let curdir = std::env::current_dir().unwrap();
36    //curdir.push("examples/test3.shm");
37    println!("{}", curdir.display());
38   // let lex = lexer::Lexer::from_file(curdir).unwrap();
39    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
40
41    let res = schm.run_from_file("examples/test3.shm", None).unwrap();
42
43    println!("{:?}", res);
44
45    let resser = res.get("test1").unwrap().clone();
46
47
48
49    let mut curdir = std::env::current_dir().unwrap();
50    curdir.push("examples/test2.shm");
51
52
53    let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap();
54
55    let dyn_res = environment::DynEnvironment::run_from_file(curdir, dynenv).unwrap();
56
57    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
58
59    //println!("dynproc:\n{:?}\n", dyn_res);
60
61    let serialized = serde_json::to_string(&ret).unwrap();
62
63    println!("Result:\n{}", serialized);
64
65    let _deserialized: CommonLevels = serde_json::from_str(&serialized).unwrap();
66
67    let lvls = 
68        Levels
69        {
70            name: "testing1234".to_string(),
71            ch_a: Some(100),
72            ch_b: 2,
73            g_type: vec![GeomType::Line(4, 6, 5), GeomType::Ray{l: 56, w: 44}, GeomType::Test],
74            arr: vec![1, 2, 3, 4]
75        };
76
77    let cl = CommonLevels{lvl: lvls};
78
79    let serialized_nat = serde_json::to_string(&cl).unwrap();
80
81    println!("nat:{}", serialized_nat);
82    println!("ser:{}", serialized);
83
84    if serialized != serialized_nat
85    {
86        println!("not equal");
87    }
88
89    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
90
91    println!("Structures: ");
92    match resser.generate_rust_code(&mut rc)
93    {
94        Ok(_) => 
95        {
96            println!("{}", rc);
97        },
98        Err(e) => 
99        {
100            println!("{}", e);
101        }
102    }
103}
Source

pub fn clone_scheme(&self) -> Arc<Serializator>

Clones the reference [Rc] to Serializator instance.

Source

pub fn get_scheme(&self) -> &Serializator

Borrows the reference to Serializator instance.

Source

pub fn get_procedure(&self, key: &String) -> Option<&Arc<Procedure>>

Attempts to get a [DynValue] from the list of the declated procedures and definitions.

Source

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

Source

pub fn get_symbols(&self, key: &String) -> Option<&Arc<Define>>

Source

pub fn from_file<F>( file_path: F, serializator: Arc<Serializator>, ) -> DynSchmRes<(Arc<DynEnvironment>, Arc<DynProcedure>)>
where F: AsRef<Path>,

This function reads dynamic config scheme with the provided serializator instance which describes how to read specified file and how to serialize it.

§Arguments
  • file_path - AsRef to Path a path to the destination file.

  • serializator - [Rc] Serializator instance which contains information about how to read and serialize the file.

§Returns

A [DynamicSchemeRes] is returned with:

  • Result::Ok with the inner tuple 0:“Rc” 1:“[Rc] DynProcedure

    • 0 a prepared dynamic environment which can be reused
    • 1 a dynamic environment which contains data
  • Result::Err with error description

Examples found in repository?
examples/error_descr_test/errtest.rs (line 24)
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(None, &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}
More examples
Hide additional examples
examples/test2.rs (line 40)
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(Some(&curdir),&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/another/another.rs (line 43)
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 47)
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}
examples/test10.rs (line 35)
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 42)
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}
Source

pub fn run_from_file<P>( file_path: P, env: Arc<DynEnvironment>, ) -> DynSchmRes<Arc<DynProcedure>>
where P: AsRef<Path>,

Read the user config file agains the DynEnvironment instance.

§Arguments
  • file_path - AsRef to Path a path to the destination file.

  • env - [Rc] DynEnvironment a instance to the pre-initialized dynamic environment which will be used to read the config.

§Returns

A [DynamicSchemeRes] is returned with:

Examples found in repository?
examples/test3.rs (line 55)
33fn main()
34{
35    let curdir = std::env::current_dir().unwrap();
36    //curdir.push("examples/test3.shm");
37    println!("{}", curdir.display());
38   // let lex = lexer::Lexer::from_file(curdir).unwrap();
39    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
40
41    let res = schm.run_from_file("examples/test3.shm", None).unwrap();
42
43    println!("{:?}", res);
44
45    let resser = res.get("test1").unwrap().clone();
46
47
48
49    let mut curdir = std::env::current_dir().unwrap();
50    curdir.push("examples/test2.shm");
51
52
53    let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap();
54
55    let dyn_res = environment::DynEnvironment::run_from_file(curdir, dynenv).unwrap();
56
57    let ret = serializator::Serialization::serialize(resser.clone(), dyn_res.clone()).unwrap();
58
59    //println!("dynproc:\n{:?}\n", dyn_res);
60
61    let serialized = serde_json::to_string(&ret).unwrap();
62
63    println!("Result:\n{}", serialized);
64
65    let _deserialized: CommonLevels = serde_json::from_str(&serialized).unwrap();
66
67    let lvls = 
68        Levels
69        {
70            name: "testing1234".to_string(),
71            ch_a: Some(100),
72            ch_b: 2,
73            g_type: vec![GeomType::Line(4, 6, 5), GeomType::Ray{l: 56, w: 44}, GeomType::Test],
74            arr: vec![1, 2, 3, 4]
75        };
76
77    let cl = CommonLevels{lvl: lvls};
78
79    let serialized_nat = serde_json::to_string(&cl).unwrap();
80
81    println!("nat:{}", serialized_nat);
82    println!("ser:{}", serialized);
83
84    if serialized != serialized_nat
85    {
86        println!("not equal");
87    }
88
89    let mut rc = RustCode::new(vec![RustCodeDerives::Debug], vec![], None);
90
91    println!("Structures: ");
92    match resser.generate_rust_code(&mut rc)
93    {
94        Ok(_) => 
95        {
96            println!("{}", rc);
97        },
98        Err(e) => 
99        {
100            println!("{}", e);
101        }
102    }
103}
Source

pub fn run( nodes: DynNodeData, env: Arc<DynEnvironment>, ) -> DynSchmRes<Arc<DynProcedure>>

Run from parsed (using lexer) content agains the DynEnvironment instance.

Examples found in repository?
examples/enum_arg/enum_arg.rs (line 81)
37pub fn main()
38{
39    let mut curdir = std::env::current_dir().unwrap(); 
40    curdir.push("examples/struct_to_scheme/enum_arg/init_enum.shm");
41    println!("{}", curdir.display());
42
43    let schm = init::SchemeInit::new_with_path("examples/enum_arg").unwrap();
44
45    let res = schm.run_from_file("init_enum.shm", None).unwrap();
46
47    let resser = res.get("test1").unwrap().clone();
48
49    println!("Static: \n{:?}\n", res);
50
51
52    let mut curdir = std::env::current_dir().unwrap();
53    curdir.push("examples/enum_arg/enum.shm");
54
55
56    let (_, dynres) = environment::DynEnvironment::from_file(&curdir, resser.clone()).unwrap();
57
58    let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
59
60    let serialized = serde_json::to_string(&ret).unwrap();
61
62
63    let n: CommonLevels = serde_json::from_str(&serialized).unwrap();
64
65    let scmp = from_struct(n, resser.clone());
66    
67    if scmp.is_err() == true
68    {
69        panic!("{}", scmp.err().unwrap());
70    }
71    else
72    {
73        let out_res = scmp.unwrap();
74        println!("{}", out_res);
75
76        let lex_out = Lexer::from_str(&out_res.to_string(), "test").unwrap();
77
78        let dyn_root = environment::DynEnvironment::new_root(resser.clone()).unwrap();
79
80        let dyn_res =
81            environment::DynEnvironment::run(lex_out, dyn_root);
82
83        if dyn_res.is_err() == true
84        {
85            println!("{}", dyn_res.err().unwrap());
86        }
87    }
88}
More examples
Hide additional examples
examples/struct_to_scheme/advanced4/struct2scheme.rs (line 257)
199pub fn main()
200{
201
202// static
203    let mut curdir = std::env::current_dir().unwrap();
204    curdir.push("examples/struct_to_scheme/advanced4");
205    println!("{}", curdir.display());
206
207    let schm = init::SchemeInit::new_with_path(curdir).unwrap();
208    let res = schm.run_from_file("init_logdaemon.shm", None).unwrap();
209    let resser = res.get("logdaemon").unwrap().clone();
210
211// dynamic
212    let mut curdir = std::env::current_dir().unwrap();
213    curdir.push("examples/struct_to_scheme/advanced4/logdaemon.shm");
214    let (_, dynres) = 
215        environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap();
216
217// serialize dyn
218    let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
219
220    let serialized = serde_json::to_string(&ret).unwrap();
221
222/*
223    let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]);
224    println!("Structures: ");
225    match resser.generate_rust_structs(&mut rc)
226    {
227        Ok(_) => 
228        {
229            println!("{}", rc);
230        },
231        Err(e) => 
232        {
233            println!("{}", e);
234        }
235    }
236*/
237
238
239    let n: LdLogDaemon = serde_json::from_str(&serialized).unwrap();
240
241    let scmp = from_struct(n, resser.clone());
242    
243    if scmp.is_err() == true
244    {
245        panic!("{}", scmp.err().unwrap());
246    }
247    else
248    {
249        let out_res = scmp.unwrap();
250        println!("{}", out_res);
251
252        let lex_out = Lexer::from_str(&out_res.to_string(), "test").unwrap();
253
254        let dyn_root = environment::DynEnvironment::new_root(resser.clone()).unwrap();
255
256        let dyn_res =
257            environment::DynEnvironment::run(lex_out, dyn_root);
258
259        if dyn_res.is_err() == true
260        {
261            println!("{}", dyn_res.err().unwrap());
262        }
263
264
265    }
266    
267}

Trait Implementations§

Source§

impl Clone for DynEnvironment

Source§

fn clone(&self) -> DynEnvironment

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 DynEnvironment

Source§

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

Formats the value using the given formatter. 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, 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.