Lines Matching refs:cell
3 cell::Cell,
23 let cell = CELL;
24 assert_eq!(cell.get(), Some(&12));
87 let cell: OnceCell<String> = OnceCell::new();
88 assert_eq!(cell.into_inner(), None);
89 let cell = OnceCell::new();
90 cell.set("hello".to_string()).unwrap();
91 assert_eq!(cell.into_inner(), Some("hello".to_string()));
96 let cell = OnceCell::new();
97 assert_eq!(format!("{:?}", cell), "OnceCell(Uninit)");
98 cell.set("hello".to_string()).unwrap();
99 assert_eq!(format!("{:?}", cell), "OnceCell(\"hello\")");
244 let cell = OnceCell::new();
247 cell.set(&s).unwrap();
260 use core::cell::Cell;
346 let cell: OnceCell<String> = OnceCell::new();
347 assert!(cell.get().is_none());
350 std::panic::catch_unwind(|| cell.get_or_try_init(|| -> Result<_, ()> { panic!() }));
352 assert!(cell.get().is_none());
354 assert_eq!(cell.get_or_try_init(|| Err(())), Err(()));
357 cell.get_or_try_init(|| Ok::<_, ()>("hello".to_string())),
360 assert_eq!(cell.get(), Some(&"hello".to_string()));
366 let cell: OnceCell<String> = OnceCell::new();
368 s.spawn(|_| cell.set("hello".to_string()));
369 let greeting = cell.wait();
415 let cell: OnceCell<String> = OnceCell::new();
416 assert_eq!(cell.into_inner(), None);
417 let cell = OnceCell::new();
418 cell.set("hello".to_string()).unwrap();
419 assert_eq!(cell.into_inner(), Some("hello".to_string()));
424 let cell = OnceCell::new();
425 assert_eq!(format!("{:#?}", cell), "OnceCell(Uninit)");
426 cell.set(vec!["hello", "world"]).unwrap();
428 format!("{:#?}", cell),
643 let cell: OnceCell<String> = OnceCell::new();
647 if let Some(msg) = cell.get() {
654 let _ = scope.spawn(|_| cell.set(MSG.to_owned()));
664 let cell = OnceCell::new();
668 cell.get_or_init(|| {
675 assert_eq!(cell.get(), None);
679 assert_eq!(cell.get(), Some(&"hello".to_string()));
685 let cell = OnceCell::new();
688 cell.set(&s).unwrap();
709 let cell = OnceNonZeroUsize::new();
714 cell.get_or_init(|| {
723 cell.get_or_init(|| {
733 assert_eq!(cell.get(), Some(val));
742 let cell = OnceNonZeroUsize::new();
744 assert!(cell.set(val1).is_ok());
745 assert_eq!(cell.get(), Some(val1));
747 assert!(cell.set(val2).is_err());
748 assert_eq!(cell.get(), Some(val1));
757 let cell = OnceNonZeroUsize::new();
764 let r1 = cell.get_or_init(|| {
774 let r2 = cell.get_or_init(|| {
784 assert_eq!(cell.get(), Some(val1));
790 let cell = OnceBool::new();
794 cell.get_or_init(|| {
803 cell.get_or_init(|| {
813 assert_eq!(cell.get(), Some(false));
819 let cell = OnceBool::new();
821 assert!(cell.set(false).is_ok());
822 assert_eq!(cell.get(), Some(false));
824 assert!(cell.set(true).is_err());
825 assert_eq!(cell.get(), Some(false));
875 let cell = OnceBox::new();
881 cell.get_or_init(|| {
889 cell.get_or_init(|| {
899 assert!(cell.get().is_some());
903 drop(cell);
910 let cell = OnceBox::new();
911 assert!(cell.get().is_none());
913 assert!(cell.set(Box::new(heap.new_pebble("hello"))).is_ok());
914 assert_eq!(cell.get().unwrap().val, "hello");
917 assert!(cell.set(Box::new(heap.new_pebble("world"))).is_err());
918 assert_eq!(cell.get().unwrap().val, "hello");
921 drop(cell);
928 let cell = OnceBox::new();
937 let r1 = cell.get_or_init(|| {
947 let r2 = cell.get_or_init(|| {
957 assert_eq!(cell.get(), Some(&val1));
962 let cell = OnceBox::new();
963 let res = cell.get_or_init(|| {
964 cell.get_or_init(|| Box::new("hello".to_string()));
974 let cell: OnceBox<Foo> = Default::default();
975 assert!(cell.get().is_none());