Skip to main content

PhysAddr

Struct PhysAddr 

#[repr(transparent)]
pub struct PhysAddr(u64);
Expand description

A 64-bit physical memory address.

This is a wrapper type around an u64, so it is always 8 bytes, even when compiled on non 64-bit systems. The TryFrom trait can be used for performing conversions between u64 and usize.

On x86_64, only the 52 lower bits of a physical address can be used. The top 12 bits need to be zero. This type guarantees that it always represents a valid physical address.

Tuple Fields§

§0: u64

Implementations§

§

impl PhysAddr

pub const fn new(addr: u64) -> PhysAddr

Creates a new physical address.

§Panics

This function panics if a bit in the range 52 to 64 is set.

If the memory_encryption feature has been enabled and an encryption bit has been configured, this also panics if the encryption bit is manually set in the address.

pub const fn new_truncate(addr: u64) -> PhysAddr

Creates a new physical address, throwing bits 52..64 away.

pub const unsafe fn new_unsafe(addr: u64) -> PhysAddr

Creates a new physical address, without any checks.

§Safety

You must make sure bits 52..64 are zero. This is not checked.

pub const fn try_new(addr: u64) -> Result<PhysAddr, PhysAddrNotValid>

Tries to create a new physical address.

Fails if any bits in the range 52 to 64 are set. If the memory_encryption feature has been enabled and an encryption bit has been configured, this also fails if the encryption bit is manually set in the address.

pub const fn zero() -> PhysAddr

Creates a physical address that points to 0.

pub const fn as_u64(self) -> u64

Converts the address to an u64.

pub const fn is_null(self) -> bool

Convenience method for checking if a physical address is null.

pub fn align_up<U>(self, align: U) -> PhysAddr
where U: Into<u64>,

Aligns the physical address upwards to the given alignment.

See the align_up function for more information.

§Panics

This function panics if the resulting address has a bit in the range 52 to 64 set.

pub fn align_down<U>(self, align: U) -> PhysAddr
where U: Into<u64>,

Aligns the physical address downwards to the given alignment.

See the align_down function for more information.

pub fn is_aligned<U>(self, align: U) -> bool
where U: Into<u64>,

Checks whether the physical address has the demanded alignment.

Trait Implementations§

§

impl Add<u64> for PhysAddr

§

type Output = PhysAddr

The resulting type after applying the + operator.
§

fn add(self, rhs: u64) -> <PhysAddr as Add<u64>>::Output

Performs the + operation. Read more
§

impl AddAssign<u64> for PhysAddr

§

fn add_assign(&mut self, rhs: u64)

Performs the += operation. Read more
§

impl Binary for PhysAddr

§

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

Formats the value using the given formatter. Read more
§

impl Clone for PhysAddr

§

fn clone(&self) -> PhysAddr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
§

impl Copy for PhysAddr

§

impl Debug for PhysAddr

§

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

Formats the value using the given formatter. Read more
§

impl Eq for PhysAddr

§

impl Hash for PhysAddr

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl LowerHex for PhysAddr

§

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

Formats the value using the given formatter. Read more
§

impl Octal for PhysAddr

§

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

Formats the value using the given formatter. Read more
§

impl Ord for PhysAddr

§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

Restrict a value to a certain interval. Read more
§

impl PartialEq for PhysAddr

§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
§

impl PartialOrd for PhysAddr

§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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
§

impl Pointer for PhysAddr

§

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

Formats the value using the given formatter. Read more
§

impl StructuralPartialEq for PhysAddr

§

impl Sub for PhysAddr

§

type Output = u64

The resulting type after applying the - operator.
§

fn sub(self, rhs: PhysAddr) -> <PhysAddr as Sub>::Output

Performs the - operation. Read more
§

impl Sub<u64> for PhysAddr

§

type Output = PhysAddr

The resulting type after applying the - operator.
§

fn sub(self, rhs: u64) -> <PhysAddr as Sub<u64>>::Output

Performs the - operation. Read more
§

impl SubAssign<u64> for PhysAddr

§

fn sub_assign(&mut self, rhs: u64)

Performs the -= operation. Read more
§

impl UpperHex for PhysAddr

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.