Expand description
Basic functions for dealing with memory, values, and types.
The contents of this module can be seen as belonging to a few families:
-
drop,replace,swap, andtakeare safe functions for moving values in particular ways. They are useful in everyday Rust code. -
size_of,size_of_val,align_of,align_of_val, andoffset_ofgive information about the representation of values in memory. -
discriminantallows comparing the variants ofenumvalues while ignoring their fields. -
forgetandManuallyDropprevent destructors from running, which is used in certain kinds of ownership transfer.needs_droptells you whether a type’s destructor even does anything. -
transmute,transmute_copy, andMaybeUninitconvert and construct values inunsafeways.
See also the alloc and ptr modules for more primitive operations on memory.
Modules§
- type_
info Experimental - MVP for exposing compile-time information about types in a runtime or const-eval processable way.
Macros§
- offset_
of - Expands to the offset in bytes of a field from the beginning of the given type.
Structs§
- Discriminant
validated - Opaque type representing the discriminant of an enum.
- Manually
Drop validated - A wrapper to inhibit the compiler from automatically calling
T’s destructor. This wrapper is 0-cost. - Alignment
Experimental validated - A type storing a
usizewhich is a power of two, and thus represents a possible alignment in the Rust abstract machine. - Assume
Experimental - Configurable proof assumptions of
TransmuteFrom. - Drop
Guard Experimental - Wrap a value and run a closure when dropped.
- Maybe
Dangling Experimental validated - Allows wrapped references and boxes to dangle.
Traits§
- Transmute
From Experimental - Marks that
Srcis transmutable intoSelf.
Functions§
- align_
of validated - Returns the ABI-required minimum alignment of a type in bytes.
- align_
of_ val validated - Returns the ABI-required minimum alignment of the type of the value that
valpoints to in bytes. - discriminant
validated - Returns a value uniquely identifying the enum variant in
v. - drop
validated - Disposes of a value.
- forget
validated - Takes ownership and “forgets” about the value without running its destructor.
- min_
align_ of Deprecated - Returns the ABI-required minimum alignment of a type in bytes.
- min_
align_ of_ val Deprecated - Returns the ABI-required minimum alignment of the type of the value that
valpoints to in bytes. - needs_
drop validated - Returns
trueif dropping values of typeTmatters. - replace
validated - Moves
srcinto the referenceddest, returning the previousdestvalue. - size_of
validated - Returns the size of a type in bytes.
- size_
of_ val validated - Returns the size of the pointed-to value in bytes.
- swap
validated - Swaps the values at two mutable locations, without deinitializing either one.
- take
validated - Replaces
destwith the default value ofT, returning the previousdestvalue. - transmute⚠
validated - Reinterprets the bits of a value of one type as another type.
- transmute_
copy ⚠validated - Interprets
srcas having type&Dst, and then readssrcwithout moving the contained value. - uninitialized⚠
Deprecated - Bypasses Rust’s normal memory-initialization checks by pretending to
produce a value of type
T, while doing nothing at all. - zeroed⚠
validated - Returns the value of type
Trepresented by the all-zero byte-pattern. - align_
of_ ⚠val_ raw Experimental - Returns the ABI-required minimum alignment of the type of the value that
valpoints to in bytes. - conjure_
zst ⚠Experimental validated - Create a fresh instance of the inhabited ZST type
T. - copy
Experimental - Bitwise-copies a value.
- forget_
unsized Experimental - Like
forget, but also accepts unsized values. - size_
of_ ⚠val_ raw Experimental validated - Returns the size of the pointed-to value in bytes.
- variant_
count Experimental - Returns the number of variants in the enum type
T.
Unions§
- Maybe
Uninit - A wrapper type to construct uninitialized instances of
T.