pub struct Address<T, U>(/* private fields */);
Expand description
An address
This newtype is used to represent addresses of a given type.
The most important invariant of this type is that the address is always
properly aligned for the given type U
. The only way to convert between
addresses of different types is to choose a new alignment (raise or lower).
This type does not, however, track lifetime. You’re on your own.
Unlike the naked underlying types, you can infallibly convert between,
for example, an Address<usize, ()>
and an Address<u64, ()>
wherever
such a conversion is lossless given the target CPU architecture.
Implementations§
Source§impl<T, U> Address<T, U>
impl<T, U> Address<T, U>
Sourcepub const unsafe fn unchecked(value: T) -> Self
pub const unsafe fn unchecked(value: T) -> Self
Creates a new Address
from a raw inner type without checking
§Safety
This function is unsafe because it does not enforce the main constraint of this type that the address stored is properly aligned to the type.
For a safe version of this constructor, first create an Address<T, ()>
from the raw value and then align to the type you want.
Source§impl<T, U> Address<T, U>
impl<T, U> Address<T, U>
Sourcepub fn as_ptr(self) -> *const U
pub fn as_ptr(self) -> *const U
Returns a raw pointer to its inner type
§Safety
Behavior is undefined, if the pointer is used and is not aligned or points to uninitialized memory.
Sourcepub fn as_mut_ptr(self) -> *mut U
pub fn as_mut_ptr(self) -> *mut U
Returns a raw pointer to its inner type
§Safety
Behavior is undefined, if the pointer is used and is not aligned or points to uninitialized memory.
Trait Implementations§
Source§impl<T, U> AddAssign<Offset<T, U>> for Address<T, U>
impl<T, U> AddAssign<Offset<T, U>> for Address<T, U>
Source§fn add_assign(&mut self, rhs: Offset<T, U>)
fn add_assign(&mut self, rhs: Offset<T, U>)
+=
operation. Read moreSource§impl<T, U> From<*const U> for Address<T, U>
Convert a const pointer to an Address
with the same type
impl<T, U> From<*const U> for Address<T, U>
Convert a const pointer to an Address
with the same type
Source§impl<T, U> From<*mut U> for Address<T, U>
Convert a mutable pointer to an Address
with the same type
impl<T, U> From<*mut U> for Address<T, U>
Convert a mutable pointer to an Address
with the same type
Source§impl<T: Ord, U> Ord for Address<T, U>
impl<T: Ord, U> Ord for Address<T, U>
Source§impl<T: PartialOrd, U> PartialOrd for Address<T, U>
impl<T: PartialOrd, U> PartialOrd for Address<T, U>
Source§impl<T, U> SubAssign<Offset<T, U>> for Address<T, U>
impl<T, U> SubAssign<Offset<T, U>> for Address<T, U>
Source§fn sub_assign(&mut self, rhs: Offset<T, U>)
fn sub_assign(&mut self, rhs: Offset<T, U>)
-=
operation. Read more