use serde::{Serialize, Deserialize}; use shm_rs::lexer::lexer; use shm_rs::scheme_composer::composer::from_struct; use shm_rs::serializator::serializator; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; /*#[derive(Clone, Debug, Serialize, Deserialize)] pub struct Level3 { pub lvl3_name: String, pub lvl3_len: i64 } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Network { pub lvl_names: Vec, pub levels: Vec }*/ #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Level3 { //pub lvl3_name: String, pub lvl3_len: i64 } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Network { pub lvl_tag: String, pub lvl_names: Vec, pub levels: Vec } pub fn main() { let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/advanced_arg/init_shm_2.shm"); println!("{}", curdir.display()); let lex = lexer::Lexer::from_file(curdir).unwrap(); let schm = init::SchemeInit::new().unwrap(); let res = schm.run(&lex, None).unwrap(); let resser = res.get("levels").unwrap().clone(); println!("Static: \n{:?}\n", res); let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/advanced_arg/data_shm_2.shm"); let lex = lexer::Lexer::from_file(curdir).unwrap(); let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap(); let dynres = environment::DynEnvironment::run(&lex, dynenv).unwrap(); let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap(); let serialized = serde_json::to_string(&ret).unwrap(); /* let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]); println!("Structures: "); match resser.generate_rust_structs(&mut rc) { Ok(_) => { println!("{}", rc); }, Err(e) => { println!("{}", e); } }*/ let n: Network = serde_json::from_str(&serialized).unwrap(); let resser = from_struct(n, resser); if resser.is_err() == true { panic!("{}", resser.err().unwrap()); } else { println!("{}", resser.unwrap()); } }