#[repr(transparent)]
pub struct Address<T, U>(_, _);
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

The NULL address

Creates a new address

Panics if the value is not properly aligned.

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.

Converts an Address to its raw inner type

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.

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.

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

Succeeds only, if they have compatible alignment

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

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

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Formats the value using the given formatter.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

Convert a reference to an Address with the same type

Converts to this type from the input type.

Convert a const pointer to an Address with the same type

Converts to this type from the input type.

Convert a mutable pointer to an Address with the same type

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Convert a raw address value to an untyped Address

Converts to this type from the input type.

Formats the value using the given formatter.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Formats the value using the given formatter.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.