Struct Address

Source
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: Zero, U> Address<T, U>

Source

pub const NULL: Address<T, U>

The NULL address

Source§

impl<U> Address<usize, U>

Source

pub const fn new(value: usize) -> Self

Creates a new address

Panics if the value is not properly aligned.

Source§

impl<T, U> Address<T, U>

Source

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

pub fn raw(self) -> T

Converts an Address to its raw inner type

Source§

impl<T, U> Address<T, U>
where Self: Into<Address<usize, U>>,

Source

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.

Source

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.

Source§

impl<T, U> Address<T, U>
where Self: Into<Address<usize, U>> + From<Address<usize, U>>,

Source

pub fn try_cast<V>(self) -> Result<Address<T, V>, AlignmentError>

Try casting an existing Address into an Address of a different type

Succeeds only, if they have compatible alignment

Source§

impl<T, U> Address<T, U>
where Offset<usize, ()>: Into<Offset<T, ()>>, T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Div<T, Output = T> + One,

Source

pub fn raise<V>(self) -> Address<T, V>

Cast an existing Address into an Address of a different type by aligning up

Source

pub fn lower<V>(self) -> Address<T, V>

Cast an existing Address into an Address of a different type by aligning down

Trait Implementations§

Source§

impl<T, U> Add<Offset<T, U>> for Address<T, U>
where Offset<usize, ()>: Into<Offset<T, ()>>, T: Mul<T, Output = T> + Add<T, Output = T>,

Source§

type Output = Address<T, U>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Offset<T, U>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, U> AddAssign<Offset<T, U>> for Address<T, U>
where Offset<usize, ()>: Into<Offset<T, ()>>, T: Mul<T, Output = T> + AddAssign<T>,

Source§

fn add_assign(&mut self, rhs: Offset<T, U>)

Performs the += operation. Read more
Source§

impl<T: Binary, U> Binary for Address<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone, U: Clone> Clone for Address<T, U>

Source§

fn clone(&self) -> Address<T, U>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: LowerHex, U> Debug for Address<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default, U: Default> Default for Address<T, U>

Source§

fn default() -> Address<T, U>

Returns the “default value” for a type. Read more
Source§

impl<T: Display, U> Display for Address<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> From<&U> for Address<T, U>
where Address<usize, U>: Into<Address<T, U>>,

Convert a reference to an Address with the same type

Source§

fn from(value: &U) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<*const U> for Address<T, U>
where Address<usize, U>: Into<Address<T, U>>,

Convert a const pointer to an Address with the same type

Source§

fn from(value: *const U) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<*mut U> for Address<T, U>
where Address<usize, U>: Into<Address<T, U>>,

Convert a mutable pointer to an Address with the same type

Source§

fn from(value: *mut U) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<Address<T, U>> for Register<T>
where Register<T>: From<T>,

Source§

fn from(value: Address<T, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<Address<u32, U>> for Address<usize, U>

Source§

fn from(value: Address<u32, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<Address<u64, U>> for Address<usize, U>

Source§

fn from(value: Address<u64, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<Address<usize, U>> for Address<u64, U>

Source§

fn from(value: Address<usize, U>) -> Self

Converts to this type from the input type.
Source§

impl<T: From<Register<T>>> From<Register<T>> for Address<T, ()>

Source§

fn from(value: Register<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Address<T, ()>

Convert a raw address value to an untyped Address

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: LowerHex, U> LowerHex for Address<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord, U> Ord for Address<T, U>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq, U> PartialEq for Address<T, U>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd, U> PartialOrd for Address<T, U>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, U> Pointer for Address<T, U>
where Self: Into<Address<usize, U>> + Copy,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> Sub<Offset<T, U>> for Address<T, U>
where Offset<usize, ()>: Into<Offset<T, ()>>, T: Mul<T, Output = T> + Sub<T, Output = T>,

Source§

type Output = Address<T, U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Offset<T, U>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U> Sub for Address<T, U>
where Offset<usize, ()>: Into<Offset<T, ()>>, T: Mul<T, Output = T> + Sub<T, Output = T> + Div<T, Output = T> + One,

Source§

type Output = Offset<T, U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Address<T, U>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U> SubAssign<Offset<T, U>> for Address<T, U>
where Offset<usize, ()>: Into<Offset<T, ()>>, T: Mul<T, Output = T> + SubAssign<T>,

Source§

fn sub_assign(&mut self, rhs: Offset<T, U>)

Performs the -= operation. Read more
Source§

impl<T: UpperHex, U> UpperHex for Address<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy, U: Copy> Copy for Address<T, U>

Source§

impl<T: Eq, U> Eq for Address<T, U>

Auto Trait Implementations§

§

impl<T, U> Freeze for Address<T, U>
where T: Freeze,

§

impl<T, U> RefUnwindSafe for Address<T, U>

§

impl<T, U> Send for Address<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for Address<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for Address<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for Address<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.