1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//! Utility for taking the value from a `Cell<Option<T>>` without cloning. //! //! After taking, the cell will have a `None`. //! //! ## Example //! //! ```rust //! use take_cell_option::take; //! use core::cell::Cell; //! //! let cell = Cell::new(Some(Box::new(10))); //! let v = take(&cell); //! assert_eq!(*v.unwrap(), 10); //! assert!(cell.into_inner().is_none()); //! ``` #![no_std] use core::cell::Cell; pub fn take<T>(co: &Cell<Option<T>>) -> Option<T> { co.replace(None) }