File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,19 @@ impl<T: UnwindSafe> UnwindSafe for SyncOnceCell<T> {}
87
87
88
88
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
89
89
impl < T > Default for SyncOnceCell < T > {
90
+ /// Creates a new empty cell.
91
+ ///
92
+ /// # Example
93
+ ///
94
+ /// ```
95
+ /// #![feature(once_cell)]
96
+ ///
97
+ /// use std::lazy::SyncOnceCell;
98
+ ///
99
+ /// fn main() {
100
+ /// assert_eq!(SyncOnceCell::<()>::new(), SyncOnceCell::default());
101
+ /// }
102
+ /// ```
90
103
fn default ( ) -> SyncOnceCell < T > {
91
104
SyncOnceCell :: new ( )
92
105
}
@@ -118,6 +131,23 @@ impl<T: Clone> Clone for SyncOnceCell<T> {
118
131
119
132
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
120
133
impl < T > From < T > for SyncOnceCell < T > {
134
+ /// Create a new cell with its contents set to `value`.
135
+ ///
136
+ /// # Example
137
+ ///
138
+ /// ```
139
+ /// #![feature(once_cell)]
140
+ ///
141
+ /// use std::lazy::SyncOnceCell;
142
+ ///
143
+ /// # fn main() -> Result<(), i32> {
144
+ /// let a = SyncOnceCell::from(3);
145
+ /// let b = SyncOnceCell::new();
146
+ /// b.set(3)?;
147
+ /// assert_eq!(a, b);
148
+ /// Ok(())
149
+ /// # }
150
+ /// ```
121
151
fn from ( value : T ) -> Self {
122
152
let cell = Self :: new ( ) ;
123
153
match cell. set ( value) {
You can’t perform that action at this time.
0 commit comments