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 {
48
48
self as _
49
49
}
50
50
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
+
51
62
/// Returns `None` if the pointer is null, or else returns a shared reference to
52
63
/// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
53
64
/// must be used instead.
Original file line number Diff line number Diff line change @@ -28,8 +28,9 @@ pub trait Pointee {
28
28
pub trait Thin = Pointee < Metadata = ( ) > ;
29
29
30
30
/// Extract the metadata component of a pointer.
31
+ #[ rustc_const_unstable( feature = "ptr_metadata" , issue = /* FIXME */ "none" ) ]
31
32
#[ 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 {
33
34
// SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T
34
35
// and PtrComponents<T> have the same memory layouts. Only std can make this
35
36
// guarantee.
Original file line number Diff line number Diff line change @@ -47,6 +47,17 @@ impl<T: ?Sized> *mut T {
47
47
self as _
48
48
}
49
49
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
+
50
61
/// Returns `None` if the pointer is null, or else returns a shared reference to
51
62
/// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
52
63
/// must be used instead.
Original file line number Diff line number Diff line change @@ -193,6 +193,17 @@ impl<T: ?Sized> NonNull<T> {
193
193
}
194
194
}
195
195
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
+
196
207
/// Acquires the underlying `*mut` pointer.
197
208
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
198
209
#[ rustc_const_stable( feature = "const_nonnull_as_ptr" , since = "1.32.0" ) ]
You can’t perform that action at this time.
0 commit comments