@@ -729,6 +729,20 @@ impl<T: ?Sized, A: AllocRef> Box<T, A> {
729
729
let reference = unsafe { & mut * manually_drop. 0 . as_ptr ( ) } ;
730
730
( reference, alloc)
731
731
}
732
+
733
+ /// Returns a shared reference to the allocator backing this `Box`.
734
+ #[ inline]
735
+ #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
736
+ pub fn alloc ( & self ) -> & A {
737
+ & self . 1
738
+ }
739
+
740
+ /// Returns a mutable reference to the allocator backing this `Box`.
741
+ #[ inline]
742
+ #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
743
+ pub fn alloc_mut ( & mut self ) -> & mut A {
744
+ & mut self . 1
745
+ }
732
746
}
733
747
734
748
impl < T : ?Sized , A : AllocRef > Box < T , A > {
@@ -794,7 +808,7 @@ impl<T: Clone, A: AllocRef + Clone> Clone for Box<T, A> {
794
808
#[ rustfmt:: skip]
795
809
#[ inline]
796
810
fn clone ( & self ) -> Self {
797
- Self :: new_in ( ( * * self ) . clone ( ) , self . 1 . clone ( ) )
811
+ Self :: new_in ( ( * * self ) . clone ( ) , self . alloc ( ) . clone ( ) )
798
812
}
799
813
800
814
/// Copies `source`'s contents into `self` without creating a new allocation.
@@ -825,7 +839,7 @@ impl<A: AllocRef + Clone> Clone for Box<str, A> {
825
839
fn clone ( & self ) -> Self {
826
840
let slice = self . as_bytes ( ) ;
827
841
let len = slice. len ( ) ;
828
- let buf = RawVec :: with_capacity_in ( len, self . 1 . clone ( ) ) ;
842
+ let buf = RawVec :: with_capacity_in ( len, self . alloc ( ) . clone ( ) ) ;
829
843
unsafe {
830
844
ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , buf. ptr ( ) , len) ;
831
845
from_boxed_utf8_unchecked ( buf. into_box ( slice. len ( ) ) . assume_init ( ) )
@@ -1272,9 +1286,9 @@ impl<I> FromIterator<I> for Box<[I]> {
1272
1286
}
1273
1287
1274
1288
#[ stable( feature = "box_slice_clone" , since = "1.3.0" ) ]
1275
- impl < T : Clone > Clone for Box < [ T ] > {
1289
+ impl < T : Clone , A : AllocRef + Clone > Clone for Box < [ T ] , A > {
1276
1290
fn clone ( & self ) -> Self {
1277
- self . to_vec ( ) . into_boxed_slice ( )
1291
+ self . to_vec_in ( self . alloc ( ) . clone ( ) ) . into_boxed_slice ( )
1278
1292
}
1279
1293
}
1280
1294
0 commit comments