use shared::Data; use std::collections::HashMap; fn main() { // Let's quickly populate a map let mut map: HashMap = HashMap::from([ ("gravity".to_string(), Data::from(9.81_f32)), ("life".to_string(), Data::from(42_i32)), ("cat".to_string(), Data::from("meow".to_string())), ]); // Hmm... ok, looks good. map.insert("direct_insert".to_string(), Data::Bool(true)); // Now to stuff it into a single thing... let map: Data = Data::from(map); // Poof! (Now as of v0.1.1 we can't directly insert or get out, as Vec and HashMap have different parameters) // Ok let's pull it all back out let m: Result, ()> = map.clone().try_into(); if let Ok(m) = m { println!("m is {:?}", m); } else { println!("{:?}", map); } // Notice: Even with `cast_into` feature, this type of try_into will fail on any other Data variant (Capt. Obvious: Well yeah, the others are primitives so we could cast them) }