@@ -11,10 +11,10 @@ use ::core::alloc::Layout;
11
11
use :: core:: mem;
12
12
use :: core:: ptr:: { self , NonNull } ;
13
13
14
- pub use allocator_api2:: alloc:: { AllocError , Allocator , Global } ;
14
+ pub use allocator_api2:: alloc:: { AllocError , Allocator } ;
15
15
16
16
#[ cfg( feature = "alloc" ) ]
17
- pub use allocator_api2:: boxed;
17
+ pub use allocator_api2:: { alloc :: Global , boxed:: Box } ;
18
18
19
19
/// Explicitly duplicate an object using the specified Allocator.
20
20
pub trait TryCloneIn : Sized {
@@ -81,3 +81,24 @@ mod impls {
81
81
}
82
82
}
83
83
}
84
+
85
+ /// Allows turning a [`Box<T: Sized, A>`][Box] into a [`Box<U: ?Sized, A>`][Box] where `T` can be
86
+ /// unsizing-coerced into a `U`.
87
+ ///
88
+ /// See [allocator_api2::unsize_box] for an explanation why this macro is necessary.
89
+ #[ cfg( feature = "alloc" ) ]
90
+ #[ doc( inline) ]
91
+ pub use crate :: __unsize_box as unsize_box;
92
+
93
+ // We have to reimplement this macro because the original implementation is not reexportable.
94
+ // Macro definitions float to the top of the crate, thus we also mark it as hidden and reexport
95
+ // again from the right namespace.
96
+ #[ cfg( feature = "alloc" ) ]
97
+ #[ doc( hidden) ]
98
+ #[ macro_export]
99
+ macro_rules! __unsize_box {
100
+ ( $boxed: expr $( , ) ? ) => { {
101
+ let ( ptr, alloc) = $crate:: allocator:: Box :: into_raw_with_allocator( $boxed) ;
102
+ unsafe { $crate:: allocator:: Box :: from_raw_in( ptr as * mut _, alloc) }
103
+ } } ;
104
+ }
0 commit comments