File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,17 @@ impl<T: ?Sized> *const T {
4848 self as _
4949 }
5050
51+ /// Decompose a (possibly wide) pointer into is address and metadata components.
52+ ///
53+ /// The pointer can be later reconstructed with [`from_raw_parts`].
54+ #[ cfg( not( bootstrap) ) ]
55+ #[ unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
56+ #[ rustc_const_unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
57+ #[ inline]
58+ pub const fn to_raw_parts ( self ) -> ( * const ( ) , <T as super :: Pointee >:: Metadata ) {
59+ ( self . cast ( ) , super :: metadata ( self ) )
60+ }
61+
5162 /// Returns `None` if the pointer is null, or else returns a shared reference to
5263 /// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
5364 /// must be used instead.
Original file line number Diff line number Diff line change @@ -28,8 +28,9 @@ pub trait Pointee {
2828pub trait Thin = Pointee < Metadata = ( ) > ;
2929
3030/// Extract the metadata component of a pointer.
31+ #[ rustc_const_unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
3132#[ inline]
32- pub fn metadata < T : ?Sized > ( ptr : * const T ) -> <T as Pointee >:: Metadata {
33+ pub const fn metadata < T : ?Sized > ( ptr : * const T ) -> <T as Pointee >:: Metadata {
3334 // SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T
3435 // and PtrComponents<T> have the same memory layouts. Only std can make this
3536 // guarantee.
Original file line number Diff line number Diff line change @@ -47,6 +47,17 @@ impl<T: ?Sized> *mut T {
4747 self as _
4848 }
4949
50+ /// Decompose a (possibly wide) pointer into is address and metadata components.
51+ ///
52+ /// The pointer can be later reconstructed with [`from_raw_parts_mut`].
53+ #[ cfg( not( bootstrap) ) ]
54+ #[ unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
55+ #[ rustc_const_unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
56+ #[ inline]
57+ pub const fn to_raw_parts ( self ) -> ( * mut ( ) , <T as super :: Pointee >:: Metadata ) {
58+ ( self . cast ( ) , super :: metadata ( self ) )
59+ }
60+
5061 /// Returns `None` if the pointer is null, or else returns a shared reference to
5162 /// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
5263 /// must be used instead.
Original file line number Diff line number Diff line change @@ -193,6 +193,17 @@ impl<T: ?Sized> NonNull<T> {
193193 }
194194 }
195195
196+ /// Decompose a (possibly wide) pointer into is address and metadata components.
197+ ///
198+ /// The pointer can be later reconstructed with [`NonNull::from_raw_parts`].
199+ #[ cfg( not( bootstrap) ) ]
200+ #[ unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
201+ #[ rustc_const_unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
202+ #[ inline]
203+ pub const fn to_raw_parts ( self ) -> ( NonNull < ( ) > , <T as super :: Pointee >:: Metadata ) {
204+ ( self . cast ( ) , super :: metadata ( self . as_ptr ( ) ) )
205+ }
206+
196207 /// Acquires the underlying `*mut` pointer.
197208 #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
198209 #[ rustc_const_stable( feature = "const_nonnull_as_ptr" , since = "1.32.0" ) ]
You can’t perform that action at this time.
0 commit comments