#[repr(transparent)]pub struct Address(usize);
Expand description
Address represents an arbitrary address. This is designed to represent address and do address arithmetic mostly in a safe way, and to allow mark some operations as unsafe. This type needs to be zero overhead (memory wise and time wise). The idea is from the paper High-level Low-level Programming (VEE09) and JikesRVM.
Tuple Fields§
§0: usize
Implementations§
source§impl Address
impl Address
sourcepub fn from_mut_ptr<T>(ptr: *mut T) -> Address
pub fn from_mut_ptr<T>(ptr: *mut T) -> Address
creates Address from a mutable pointer
sourcepub const unsafe fn zero() -> Address
pub const unsafe fn zero() -> Address
creates a null Address (0)
§Safety
It is unsafe and the user needs to be aware that they are creating an invalid address.
The zero address should only be used as unininitialized or sentinel values in performance critical code (where you dont want to use Option<Address>
).
sourcepub unsafe fn max() -> Address
pub unsafe fn max() -> Address
creates an Address of (usize::MAX)
§Safety
It is unsafe and the user needs to be aware that they are creating an invalid address.
The max address should only be used as unininitialized or sentinel values in performance critical code (where you dont want to use Option<Address>
).
sourcepub const unsafe fn from_usize(raw: usize) -> Address
pub const unsafe fn from_usize(raw: usize) -> Address
creates an arbitrary Address
§Safety
It is unsafe and the user needs to be aware that they may create an invalid address. This creates arbitrary addresses which may not be valid. This should only be used for hard-coded addresses. Any other uses of this function could be replaced with more proper alternatives.
sourcepub fn shift<T>(self, offset: isize) -> Self
pub fn shift<T>(self, offset: isize) -> Self
shifts the address by N T-typed objects (returns addr + N * size_of(T))
sourcepub const fn get_extent(self, other: Address) -> ByteSize
pub const fn get_extent(self, other: Address) -> ByteSize
Get the number of bytes between two addresses. The current address needs to be higher than the other address.
sourcepub const fn get_offset(self, other: Address) -> ByteOffset
pub const fn get_offset(self, other: Address) -> ByteOffset
Get the offset from other
to self
. The result is negative is self
is lower than other
.
sourcepub const fn saturating_sub(self, size: usize) -> Address
pub const fn saturating_sub(self, size: usize) -> Address
Perform a saturating subtract on the Address
sourcepub unsafe fn load<T: Copy>(self) -> T
pub unsafe fn load<T: Copy>(self) -> T
loads a value of type T from the address
§Safety
This could throw a segment fault if the address is invalid
sourcepub unsafe fn store<T>(self, value: T)
pub unsafe fn store<T>(self, value: T)
stores a value of type T to the address
§Safety
This could throw a segment fault if the address is invalid
sourcepub unsafe fn atomic_load<T: Atomic>(self, order: Ordering) -> T::Type
pub unsafe fn atomic_load<T: Atomic>(self, order: Ordering) -> T::Type
sourcepub unsafe fn atomic_store<T: Atomic>(self, val: T::Type, order: Ordering)
pub unsafe fn atomic_store<T: Atomic>(self, val: T::Type, order: Ordering)
sourcepub unsafe fn compare_exchange<T: Atomic>(
self,
old: T::Type,
new: T::Type,
success: Ordering,
failure: Ordering
) -> Result<T::Type, T::Type>
pub unsafe fn compare_exchange<T: Atomic>( self, old: T::Type, new: T::Type, success: Ordering, failure: Ordering ) -> Result<T::Type, T::Type>
atomic operation: compare and exchange usize
§Safety
This could throw a segment fault if the address is invalid
sourcepub const fn align_up(self, align: ByteSize) -> Address
pub const fn align_up(self, align: ByteSize) -> Address
aligns up the address to the given alignment
sourcepub const fn align_down(self, align: ByteSize) -> Address
pub const fn align_down(self, align: ByteSize) -> Address
aligns down the address to the given alignment
sourcepub const fn is_aligned_to(self, align: usize) -> bool
pub const fn is_aligned_to(self, align: usize) -> bool
is this address aligned to the given alignment
sourcepub fn to_mut_ptr<T>(self) -> *mut T
pub fn to_mut_ptr<T>(self) -> *mut T
converts the Address to a mutable pointer
sourcepub unsafe fn as_ref<'a, T>(self) -> &'a T
pub unsafe fn as_ref<'a, T>(self) -> &'a T
converts the Address to a Rust reference
§Safety
The caller must guarantee the address actually points to a Rust object.
sourcepub unsafe fn as_mut_ref<'a, T>(self) -> &'a mut T
pub unsafe fn as_mut_ref<'a, T>(self) -> &'a mut T
converts the Address to a mutable Rust reference
§Safety
The caller must guarantee the address actually points to a Rust object.
sourcepub fn chunk_index(self) -> usize
pub fn chunk_index(self) -> usize
returns the chunk index for this address
Trait Implementations§
source§impl AddAssign<isize> for Address
impl AddAssign<isize> for Address
Address += ByteOffset (positive or negative)
source§fn add_assign(&mut self, offset: ByteOffset)
fn add_assign(&mut self, offset: ByteOffset)
+=
operation. Read moresource§impl AddAssign<usize> for Address
impl AddAssign<usize> for Address
Address += ByteSize (positive)
source§fn add_assign(&mut self, offset: ByteSize)
fn add_assign(&mut self, offset: ByteSize)
+=
operation. Read moresource§impl Debug for Address
impl Debug for Address
allows Debug format the Address (as upper-case hex value with 0x prefix)
source§impl Display for Address
impl Display for Address
allows Display format the Address (as upper-case hex value with 0x prefix)
source§impl Ord for Address
impl Ord for Address
source§impl PartialEq for Address
impl PartialEq for Address
source§impl PartialOrd for Address
impl PartialOrd for Address
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Slot for Address
impl Slot for Address
For backword compatibility, we let Address
implement Slot
with the same semantics as
SimpleSlot
so that existing bindings that use Address
as Slot
can continue to work.
However, we should use SimpleSlot
directly instead of using Address
. The purpose of the
Address
type is to represent an address in memory. It is not directly related to fields
that hold references to other objects. Calling load()
and store()
on an Address
does
not indicate how many bytes to load or store, or how to interpret those bytes. On the other
hand, SimpleSlot
is all about how to access a field that holds a reference represented
simply as an ObjectReference
. The intention and the semantics are clearer with
SimpleSlot
.
source§fn store(&self, object: ObjectReference)
fn store(&self, object: ObjectReference)
object
into the slot. Read moresource§fn prefetch_load(&self)
fn prefetch_load(&self)
load
will be faster.source§fn prefetch_store(&self)
fn prefetch_store(&self)
store
will be faster.source§impl SubAssign<usize> for Address
impl SubAssign<usize> for Address
Address -= ByteSize (positive)
source§fn sub_assign(&mut self, offset: ByteSize)
fn sub_assign(&mut self, offset: ByteSize)
-=
operation. Read moreimpl Copy for Address
impl Eq for Address
impl NoUninit for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnwindSafe for Address
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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