pub trait Pointee {
type Metadata: Debug + Copy + Send + Sync + Ord + Hash + Unpin + Freeze;
}
ð¬This is a nightly-only experimental API. (ptr_metadata
#81513) Expand description
Provides the pointer metadata type of any pointed-to type.
Raw pointer types and reference types in Rust can be thought of as made of two parts: a data pointer that contains the memory address of the value, and some metadata.
For statically-sized types (that implement the Sized
traits) as well as for extern
types, pointers are said to be âthinâ: metadata is zero-sized and its type is ()
.
Pointers to dynamically-sized types are said to be âwideâ or âfatâ, they have non-zero-sized metadata:
str
type, metadata is the length in bytes as usize
[T]
, metadata is the length in items as usize
dyn SomeTrait
, metadata is DynMetadata<Self>
(e.g. DynMetadata<dyn SomeTrait>
)In the future, the Rust language may gain new kinds of types that have different pointer metadata.
§ThePointee
trait
The point of this trait is its Metadata
associated type, which is ()
or usize
or DynMetadata<_>
as described above. It is automatically implemented for every type. It can be assumed to be implemented in a generic context, even without a corresponding bound.
Raw pointers can be decomposed into the data pointer and metadata components with their to_raw_parts
method.
Alternatively, metadata alone can be extracted with the metadata
function. A reference can be passed to metadata
and implicitly coerced.
A (possibly-wide) pointer can be put back together from its data pointer and metadata with from_raw_parts
or from_raw_parts_mut
.
ptr_metadata
#81513)
The type for metadata in pointers and references to Self
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4