pub trait Address: AddressValue + Sized + Default + Copy + Eq + PartialEq + Ord + PartialOrd + BitAnd<<Self as AddressValue>::V, Output = Self> + BitOr<<Self as AddressValue>::V, Output = Self> {
Show 13 methods fn new(addr: Self::V) -> Self; fn raw_value(&self) -> Self::V; fn checked_offset_from(&self, base: Self) -> Option<Self::V>; fn checked_add(&self, other: Self::V) -> Option<Self>; fn overflowing_add(&self, other: Self::V) -> (Self, bool); fn unchecked_add(&self, offset: Self::V) -> Self; fn checked_sub(&self, other: Self::V) -> Option<Self>; fn overflowing_sub(&self, other: Self::V) -> (Self, bool); fn unchecked_sub(&self, other: Self::V) -> Self; fn mask(&self, mask: Self::V) -> Self::V { ... } fn unchecked_offset_from(&self, base: Self) -> Self::V { ... } fn checked_align_up(&self, power_of_two: Self::V) -> Option<Self> { ... } fn unchecked_align_up(&self, power_of_two: Self::V) -> Self { ... }
}
Expand description

Trait to represent an address within an address space.

To simplify the design and implementation, assume the same raw data type (AddressValue::V) could be used to store address, size and offset for the address space. Thus the Address trait could be used to manage address, size and offset. On the other hand, type aliases may be defined to improve code readability.

One design rule is applied to the Address trait, namely that operators (+, -, &, | etc) are not supported and it forces clients to explicitly invoke corresponding methods. But there are always exceptions: Address (BitAnd|BitOr) AddressValue are supported.

Required Methods

Creates an address from a raw address value.

Returns the raw value of the address.

Computes the offset from this address to the given base address.

Returns None if there is underflow.

Computes self + other, returning None if overflow occurred.

Computes self + other.

Returns a tuple of the addition result along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped address is returned.

Computes self + offset.

In the event of overflow, follows standard Rust behavior, i.e. panic in debug builds, silently wrap in release builds.

Note that, unlike the unchecked_* methods in std, this method never invokes undefined behavior..

Subtracts two addresses, checking for underflow. If underflow happens, None is returned.

Computes self - other.

Returns a tuple of the subtraction result along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped address is returned.

Computes self - other.

In the event of underflow, follows standard Rust behavior, i.e. panic in debug builds, silently wrap in release builds.

Note that, unlike the unchecked_* methods in std, this method never invokes undefined behavior.

Provided Methods

Returns the bitwise and of the address with the given mask.

Computes the offset from this address to the given base address.

In the event of overflow, follows standard Rust behavior, i.e. panic in debug builds, silently wrap in release builds.

Note that, unlike the unchecked_* methods in std, this method never invokes undefined behavior.

Examples
let base = GuestAddress(0x100);
let addr = GuestAddress(0x150);
assert_eq!(addr.unchecked_offset_from(base), 0x50);

Returns self, aligned to the given power of two.

Returns self, aligned to the given power of two. Only use this when the result is guaranteed not to overflow.

Implementors