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; pub const AUTO: u64 = 0; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetMachine { pub nm_addrs: Vec } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetInterface { pub ni_ifalias: String, pub ni_ifloc: String, pub ni_addr: String, pub ni_ifmtu: Option, pub ni_ifaddr_mask: String } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetRouteTo { pub rt_dest: String, pub rt_via: Option, pub rt_metric: u64 } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetInterfaceAlias { pub if_alias: String, pub if_routes_to: Vec } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetRouteTable { pub rt_title: String, pub rt_tbls: Option> } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Network { pub net_machine: NetMachine, pub net_ifs: Vec, pub net_rt_tbls: Vec } pub fn main() { let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/struct_proc/structure.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("networking").unwrap().clone(); println!("Static: \n{:?}\n", res); /* 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 mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/struct_proc/data.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 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()); } }