We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
RefCell::take
1 parent 019ab73 commit f121f09Copy full SHA for f121f09
src/libcore/cell.rs
@@ -1023,6 +1023,27 @@ impl<T: ?Sized> RefCell<T> {
1023
}
1024
1025
1026
+impl<T: Default> RefCell<T> {
1027
+ /// Takes the wrapped value, leaving `Default::default()` in its place.
1028
+ ///
1029
+ /// # Examples
1030
1031
+ /// ```
1032
+ /// #![feature(refcell_take)]
1033
+ /// use std::cell::RefCell;
1034
1035
+ /// let c = RefCell::new(5);
1036
+ /// let five = c.take();
1037
1038
+ /// assert_eq!(five, 5);
1039
+ /// assert_eq!(c.into_inner(), 0);
1040
1041
+ #[unstable(feature = "refcell_take", issue = "71395")]
1042
+ pub fn take(&self) -> T {
1043
+ self.replace(Default::default())
1044
+ }
1045
+}
1046
+
1047
#[stable(feature = "rust1", since = "1.0.0")]
1048
unsafe impl<T: ?Sized> Send for RefCell<T> where T: Send {}
1049
0 commit comments