File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -332,6 +332,11 @@ mod once_box {
332332 OnceBox { inner : AtomicPtr :: new ( ptr:: null_mut ( ) ) , ghost : PhantomData }
333333 }
334334
335+ /// Creates a new cell with the given value.
336+ pub fn with_value ( value : Box < T > ) -> Self {
337+ OnceBox { inner : AtomicPtr :: new ( Box :: into_raw ( value) ) , ghost : PhantomData }
338+ }
339+
335340 /// Gets a reference to the underlying value.
336341 pub fn get ( & self ) -> Option < & T > {
337342 let ptr = self . inner . load ( Ordering :: Acquire ) ;
@@ -410,6 +415,15 @@ mod once_box {
410415
411416 unsafe impl < T : Sync + Send > Sync for OnceBox < T > { }
412417
418+ impl < T : Clone > Clone for OnceBox < T > {
419+ fn clone ( & self ) -> Self {
420+ match self . get ( ) {
421+ Some ( value) => OnceBox :: with_value ( Box :: new ( value. clone ( ) ) ) ,
422+ None => OnceBox :: new ( ) ,
423+ }
424+ }
425+ }
426+
413427 /// ```compile_fail
414428 /// struct S(*mut ());
415429 /// unsafe impl Sync for S {}
You can’t perform that action at this time.
0 commit comments