1 extern crate lazycell; 2 3 use lazycell::LazyCell; 4 5 #[test] test_lazycell()6fn test_lazycell() { 7 let lazycell = LazyCell::new(); 8 9 assert_eq!(lazycell.borrow(), None); 10 assert!(!lazycell.filled()); 11 12 lazycell.fill(1).unwrap(); 13 14 assert!(lazycell.filled()); 15 assert_eq!(lazycell.borrow(), Some(&1)); 16 assert_eq!(lazycell.into_inner(), Some(1)); 17 } 18 19 #[test] test_already_filled_error()20fn test_already_filled_error() { 21 let lazycell: LazyCell<usize> = LazyCell::new(); 22 23 lazycell.fill(1).unwrap(); 24 assert_eq!(lazycell.fill(1), Err(1)); 25 } 26