extern crate dungeon_cell; use dungeon_cell::bound::{bounds, Bound}; use dungeon_cell::layout::{Alignment, Size, Layout}; use dungeon_cell::vtable::LifetimeVTable; use dungeon_cell::{layout_for, DefaultVtable, DungeonCore}; use static_assertions::*; use dungeon_cell::bound::traits; use dungeon_cell::bound::traits::__; assert_not_impl_all!(DungeonCore>: Send); assert_impl_all!(DungeonCore>: Send); static TEST: DungeonCore = DungeonCore::new(42); type DebugClone = Bound<__, __, __, traits::Clone, __, traits::Debug>; fn main() { // test static println!("{:?}", TEST.borrow::()); // test debug let y: Vec> = vec![ DungeonCore::new(String::from("hello")), DungeonCore::new(1234), DungeonCore::new(123.431), ]; dbg!(y); // test clone let y: DungeonCore> = DungeonCore::new(String::from("hello")); let z = Clone::clone(&y); println!("{:?}", y.borrow::()); println!("{:?}", z.borrow::()); // test many types let mut x: DungeonCore = DungeonCore::new(()); println!("Size {}", std::mem::size_of_val(&x)); println!("Align {}", std::mem::align_of_val(&x)); dbg!(&x); println!("{:?}", x.take::()); x.store(1.234_f32); match &x { x if x.type_descriptor().is_type::() => { let x = x.borrow::().unwrap(); println!("float: {}", x); } x if x.type_descriptor().is_type::() => { let x = x.borrow::().unwrap(); println!("int: {}", x); } _ => {} } if let Some(x) = x.borrow::() { println!("float: {}", x); } else if let Some(x) = x.borrow::() { println!("int: {}", x); } dbg!(&x); println!("{:?}", x.take::()); x.store(1234_i32); println!("{:?}", x.take::()); x.store("hello"); println!("{:?}", x.take::<&'static str>()); x.store("world".to_owned()); println!("{:?}", x.take::()); x.store("a".to_owned()); x.store("b".to_owned()); println!("{:?}", x.take::()); x.store("hello".to_owned()); x.borrow_mut::().unwrap().push_str(" world"); println!("{:?}", x.borrow::()); let mut x: DungeonCore, Alignment<8>>> = x.into_larger(); println!("Size {}", std::mem::size_of_val(&x)); println!("Align {}", std::mem::align_of_val(&x)); println!("{:?}", x.borrow::()); x.store("smaller"); let x: DungeonCore, Alignment<8>>> = x.try_into_smaller().unwrap(); println!("size {}", std::mem::size_of_val(&x)); println!("align {}", std::mem::align_of_val(&x)); println!("{:?}", x.borrow::<&'static str>()); let x = x.into_less_bounds::(); std::thread::spawn(move || { println!("size {}", std::mem::size_of_val(&x)); println!("align {}", std::mem::align_of_val(&x)); println!("{:?}", x.borrow::<&'static str>()); }) .join() .unwrap(); // === let z = 42i32; let mut x: DungeonCore< layout_for!(i32, f32, &'static str, String), &LifetimeVTable, > = DungeonCore::new(&z); dbg!(x.type_descriptor()); dbg!(x.borrow::<&i32>()); x.store("hi"); dbg!(x.borrow::<&str>()); // { // let z = 123i32; // x.store(&z); // } dbg!(x.borrow::<&i32>()); let mut z = 42i32; let mut y = dungeon_cell::give_opaque_static_form!(|| z += 1); y.0(); { let mut x: DungeonCore< layout_for!(&mut i32), &LifetimeVTable, > = DungeonCore::new(y); } dbg!(z); hi(); } fn hi() { // let mut z = 42i32; // // let mut x: DungeonCore< // layout_for!(i32, f32, &'static str, String), // bounds::Normal, // &LifetimeVTable, // > = DungeonCore::new(&mut z); // // { // let mut y = 123i32; // x.store(&mut y); // } } type X<'a> = DungeonCore< layout_for!(i32, f32, &'static str, String), &'a LifetimeVTable<'a, bounds::Normal>, >; // fn evil<'a: 'b, 'b>(x: X<'a>) -> X<'b> { // x // } // // fn not_evil<'a: 'b, 'b>(x: Box<&'a i32>) -> Box<&'b i32> { // x // }