Struct const_field_offset::FieldOffset [−][src]
#[repr(transparent)]pub struct FieldOffset<T, U, PinFlag = NotPinned>(_, _);
Expand description
Represents a pointer to a field of type U
within the type T
The PinFlag
parameter can be set to AllowPin
to enable the projection
from Pin<&T> to Pin<&U>
Implementations
pub unsafe fn new<F>(f: F) -> FieldOffset<T, U, NotPinned> where
F: FnOnce(*const T) -> *const U,
pub unsafe fn new<F>(f: F) -> FieldOffset<T, U, NotPinned> where
F: FnOnce(*const T) -> *const U,
Construct a field offset via a lambda which returns a reference to the field in question.
Safety
The lambda must not dereference the provided pointer or access the inner value in any way as it may point to uninitialized memory.
For the returned FieldOffset
to be safe to use, the returned pointer
must be valid for any instance of T
. For example, returning a pointer
to a field from an enum with multiple variants will produce a FieldOffset
which is unsafe to use.
Construct a field offset directly from a byte offset.
Safety
For the returned FieldOffset
to be safe to use, the field offset
must be valid for any instance of T
. For example, returning the offset
to a field from an enum with multiple variants will produce a FieldOffset
which is unsafe to use.
Apply the field offset to a native mutable pointer.
Apply the field offset to a mutable reference.
Get the raw byte offset for this field offset.
Unapply the field offset to a native pointer.
Safety
Warning: very unsafe!
This applies a negative offset to a pointer. If the safety implications of this are not already clear to you, then do not use this method. Also be aware that Rust has stronger aliasing rules than other languages, so it may be UB to dereference the resulting pointer even if it points to a valid location, due to the presence of other live references.
Unapply the field offset to a native mutable pointer.
Safety
Warning: very unsafe!
This applies a negative offset to a pointer. If the safety implications of this are not already clear to you, then do not use this method. Also be aware that Rust has stronger aliasing rules than other languages, so it may be UB to dereference the resulting pointer even if it points to a valid location, due to the presence of other live references.
Unapply the field offset to a reference.
Safety
Warning: very unsafe!
This applies a negative offset to a reference. If the safety implications of this are not already clear to you, then do not use this method. Also be aware that Rust has stronger aliasing rules than other languages, so this method may cause UB even if the resulting reference points to a valid location, due to the presence of other live references.
Unapply the field offset to a mutable reference.
Safety
Warning: very unsafe!
This applies a negative offset to a reference. If the safety implications of this are not already clear to you, then do not use this method. Also be aware that Rust has stronger aliasing rules than other languages, so this method may cause UB even if the resulting reference points to a valid location, due to the presence of other live references.
Convert this offset to an offset that is allowed to go from Pin<&T>
to Pin<&U>
Safety
The Pin safety rules for projection must be respected. These rules are explained in the Pin documentation
Remove the AllowPin flag
Construct a field offset directly from a byte offset, which can be projected from a pinned.
Safety
In addition to the safety rules of FieldOffset::new_from_offset, the projection
from Pin<&T>
to Pin<&U>
must also be allowed. The rules are explained in the
Pin documentation
Apply the field offset to a pinned reference and return a pinned reference to the field
Apply the field offset to a pinned mutable reference and return a pinned mutable reference to the field
Trait Implementations
type Output = FieldOffset<T, V, NotPinned>
type Output = FieldOffset<T, V, NotPinned>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
type Output = FieldOffset<T, V, AllowPin>
type Output = FieldOffset<T, V, AllowPin>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
Allow chaining pointer-to-members.
Applying the resulting field offset is equivalent to applying the first field offset, then applying the second field offset.
The requirements on the generic type parameters ensure this is a safe operation.
type Output = FieldOffset<T, V, NotPinned>
type Output = FieldOffset<T, V, NotPinned>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
type Output = FieldOffset<T, V, NotPinned>
type Output = FieldOffset<T, V, NotPinned>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
The debug implementation prints the byte offset of the field in hexadecimal.
Performs the conversion.