Trait vm_memory::address::Address[][src]

pub trait Address: AddressValue + Sized + Default + Copy + Eq + PartialEq + Ord + PartialOrd + BitAnd<Self::V, Output = Self> + BitOr<Self::V, Output = Self> {
    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 { ... } }

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

fn new(addr: Self::V) -> Self[src]

Creates an address from a raw address value.

fn raw_value(&self) -> Self::V[src]

Returns the raw value of the address.

fn checked_offset_from(&self, base: Self) -> Option<Self::V>[src]

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

Returns None if there is underflow.

fn checked_add(&self, other: Self::V) -> Option<Self>[src]

Computes self + other, returning None if overflow occurred.

fn overflowing_add(&self, other: Self::V) -> (Self, bool)[src]

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.

fn unchecked_add(&self, offset: Self::V) -> Self[src]

Computes self + offset.

Results in undefined behavior when an overflow occurs.

fn checked_sub(&self, other: Self::V) -> Option<Self>[src]

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

fn overflowing_sub(&self, other: Self::V) -> (Self, bool)[src]

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.

fn unchecked_sub(&self, other: Self::V) -> Self[src]

Computes self - other.

Results in undefined behavior when an underflow occurs.

Loading content...

Provided methods

fn mask(&self, mask: Self::V) -> Self::V[src]

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

fn unchecked_offset_from(&self, base: Self) -> Self::V[src]

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

Results in undefined behavior when an underflow occurs.

Examples

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

fn checked_align_up(&self, power_of_two: Self::V) -> Option<Self>[src]

Returns self, aligned to the given power of two.

fn unchecked_align_up(&self, power_of_two: Self::V) -> Self[src]

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

Loading content...

Implementors

Loading content...