Lines Matching defs:lazycell

2 // Modified work Copyright (c) 2016-2018 Nikita Pekin and the lazycell contributors
31 //! use lazycell::LazyCell;
33 //! let lazycell = LazyCell::new();
35 //! assert_eq!(lazycell.borrow(), None);
36 //! assert!(!lazycell.filled());
37 //! lazycell.fill(1).ok();
38 //! assert!(lazycell.filled());
39 //! assert_eq!(lazycell.borrow(), Some(&1));
40 //! assert_eq!(lazycell.into_inner(), Some(1));
355 let lazycell: LazyCell<usize> = LazyCell::new();
357 let value = lazycell.borrow();
360 let value = lazycell.get();
366 let lazycell = LazyCell::new();
368 assert!(!lazycell.filled());
369 lazycell.fill(1).unwrap();
370 assert!(lazycell.filled());
372 let value = lazycell.borrow();
375 let value = lazycell.get();
381 let mut lazycell = LazyCell::new();
382 assert!(lazycell.borrow_mut().is_none());
384 lazycell.fill(1).unwrap();
385 assert_eq!(lazycell.borrow_mut(), Some(&mut 1));
387 *lazycell.borrow_mut().unwrap() = 2;
388 assert_eq!(lazycell.borrow_mut(), Some(&mut 2));
391 lazycell = LazyCell::new();
392 assert!(lazycell.borrow_mut().is_none());
397 let lazycell = LazyCell::new();
399 lazycell.fill(1).unwrap();
400 assert_eq!(lazycell.fill(1), Err(1));
405 let lazycell = LazyCell::new();
407 let value = lazycell.borrow_with(|| 1);
413 let lazycell = LazyCell::new();
414 lazycell.fill(1).unwrap();
416 let value = lazycell.borrow_with(|| 1);
422 let lazycell = LazyCell::new();
424 lazycell.fill(1).unwrap();
426 let value = lazycell.borrow_with(|| 2);
435 let lazycell: LazyCell<Box<i32>> = LazyCell::new();
439 lazycell.borrow_with(|| {
440 let _ = lazycell.fill(Box::new(1));
441 reference = lazycell.borrow().map(|r| &**r);
448 let mut lazycell = LazyCell::new();
451 let value = lazycell.borrow_mut_with(|| 1);
455 assert_eq!(&2, lazycell.borrow().unwrap());
460 let mut lazycell = LazyCell::new();
461 lazycell.fill(1).unwrap();
463 let value = lazycell.borrow_mut_with(|| 1);
469 let mut lazycell = LazyCell::new();
471 lazycell.fill(1).unwrap();
473 let value = lazycell.borrow_mut_with(|| 2);
479 let lazycell = LazyCell::new();
480 let result = lazycell.try_borrow_with::<(), _>(|| Ok(1));
486 let lazycell = LazyCell::<()>::new();
487 let result = lazycell.try_borrow_with(|| Err(1));
493 let lazycell = LazyCell::new();
494 lazycell.fill(1).unwrap();
495 let result = lazycell.try_borrow_with::<(), _>(|| unreachable!());
502 let lazycell: LazyCell<Box<i32>> = LazyCell::new();
506 let _ = lazycell.try_borrow_with::<(), _>(|| {
507 let _ = lazycell.fill(Box::new(1));
508 reference = lazycell.borrow().map(|r| &**r);
515 let mut lazycell = LazyCell::new();
517 let result = lazycell.try_borrow_mut_with::<(), _>(|| Ok(1));
521 assert_eq!(&mut 2, lazycell.borrow().unwrap());
526 let mut lazycell = LazyCell::<()>::new();
527 let result = lazycell.try_borrow_mut_with(|| Err(1));
533 let mut lazycell = LazyCell::new();
534 lazycell.fill(1).unwrap();
535 let result = lazycell.try_borrow_mut_with::<(), _>(|| unreachable!());
541 let lazycell = LazyCell::new();
543 lazycell.fill(1).unwrap();
544 let value = lazycell.into_inner();
550 let lazycell: AtomicLazyCell<usize> = AtomicLazyCell::new();
552 let value = lazycell.borrow();
555 let value = lazycell.get();
561 let lazycell = AtomicLazyCell::new();
563 assert!(!lazycell.filled());
564 lazycell.fill(1).unwrap();
565 assert!(lazycell.filled());
567 let value = lazycell.borrow();
570 let value = lazycell.get();
576 let lazycell = AtomicLazyCell::new();
578 lazycell.fill(1).unwrap();
579 assert_eq!(1, lazycell.fill(1).unwrap_err());
584 let lazycell = AtomicLazyCell::new();
586 lazycell.fill(1).unwrap();
587 let value = lazycell.into_inner();