pub trait Address:
PartialOrd
+ Copy
+ Sized {
Show 21 methods
// Required methods
fn as_usize(&self) -> usize;
fn from_usize(_: usize) -> Self;
fn verify(self) -> bool;
// Provided methods
fn plus<A: Address>(&self, bytes: usize) -> A { ... }
fn sub<A: Address>(&self, bytes: usize) -> A { ... }
fn offset<T, A: Address>(&self, offset: usize) -> A { ... }
fn load<T: Copy>(&self) -> T { ... }
fn store<T>(&self, value: T) { ... }
fn is_zero(&self) -> bool { ... }
fn align_up<A: Address>(&self, align: usize) -> A { ... }
fn gte<A: Address>(&self, addr: A) -> bool { ... }
fn greater<A: Address>(&self, addr: A) -> bool { ... }
fn lte<A: Address>(&self, addr: A) -> bool { ... }
fn less<A: Address>(&self, addr: A) -> bool { ... }
fn is_aligned_to(&self, align: usize) -> bool { ... }
fn from_ptr<T>(ptr: *const T) -> Self { ... }
fn to_ptr<T>(&self) -> *const T { ... }
fn to_ptr_mut<T>(&self) -> *mut T { ... }
fn zero() -> Self { ... }
fn diff<A: Address>(&self, another: A) -> usize { ... }
fn memset(&self, val: u8, length: usize) { ... }
}
Expand description
The Address
trait exposes all the basic operations (arithmetic, etc.) that
can be performed on an address of a Floorplan type. These are all intrinsically
unsafe operations, and intended for use by developers of the Floorplan compiler, or other developers extending the capability of Floorplan. Directly accessing these
trait functions from memory management code is ill-advised, and unsupported.
Required Methods§
Sourcefn as_usize(&self) -> usize
fn as_usize(&self) -> usize
An address can be constructed from a usize
value.
Accessing this function directly from memory management code is unsupported
Sourcefn from_usize(_: usize) -> Self
fn from_usize(_: usize) -> Self
An address can be decronstructed into a raw usize
value.
Accessing this function directly from memory management code is unsupported
Sourcefn verify(self) -> bool
fn verify(self) -> bool
Does this address appear valid accoring to the layout / address type?
Accessing this function directly from memory management code is unsupported
Provided Methods§
Sourcefn plus<A: Address>(&self, bytes: usize) -> A
fn plus<A: Address>(&self, bytes: usize) -> A
Add some number of bytes
to this address, producing an address of type A
.
Accessing this function directly from memory management code is unsupported
Sourcefn sub<A: Address>(&self, bytes: usize) -> A
fn sub<A: Address>(&self, bytes: usize) -> A
Subtract some number of bytes
from this address, producing an address of type A
.
Accessing this function directly from memory management code is unsupported
Sourcefn offset<T, A: Address>(&self, offset: usize) -> A
fn offset<T, A: Address>(&self, offset: usize) -> A
Offset this &self
address some number of instances of type T
, producing an address of
type A
.
Accessing this function directly from memory management code is unsupported
Sourcefn load<T: Copy>(&self) -> T
fn load<T: Copy>(&self) -> T
Read a single instance of a value of type T
from this address.
Accessing this function directly from memory management code is unsupported
Sourcefn store<T>(&self, value: T)
fn store<T>(&self, value: T)
Store a single instance value
into the memory at this address.
Accessing this function directly from memory management code is unsupported
Sourcefn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Is the value of this address equivalent to the (universal) null value?
Accessing this function directly from memory management code is unsupported
Sourcefn align_up<A: Address>(&self, align: usize) -> A
fn align_up<A: Address>(&self, align: usize) -> A
Align this pointer up (increasing value) to the nearest address with a value
aligned to align
bytes. For example the following properties hold:
let a = WordAddr::from_usize(0xff);
assert!(a.align_up::<WordAddr>(2).as_usize() == 0x100);
assert!(a.align_up::<WordAddr>(16).as_usize() == 0x100);
assert!(a.align_up::<WordAddr>(512).as_usize() == 0x200);
let b = WordAddr::from_usize(0x100);
assert!(b.align_up::<WordAddr>(256).as_usize() == 0x100);
Accessing this function directly from memory management code is unsupported
Sourcefn gte<A: Address>(&self, addr: A) -> bool
fn gte<A: Address>(&self, addr: A) -> bool
Is the value of this address greater than or equal to the value of the given address?
Accessing this function directly from memory management code is unsupported
Sourcefn greater<A: Address>(&self, addr: A) -> bool
fn greater<A: Address>(&self, addr: A) -> bool
Is the value of this address greater than the value of the given address?
Accessing this function directly from memory management code is unsupported
Sourcefn lte<A: Address>(&self, addr: A) -> bool
fn lte<A: Address>(&self, addr: A) -> bool
Is the value of this address less than or equal to the value of the given address?
Accessing this function directly from memory management code is unsupported
Sourcefn less<A: Address>(&self, addr: A) -> bool
fn less<A: Address>(&self, addr: A) -> bool
Is the value of this address less than the value of the given address?
Accessing this function directly from memory management code is unsupported
Sourcefn is_aligned_to(&self, align: usize) -> bool
fn is_aligned_to(&self, align: usize) -> bool
Is the value of this address exactly aligned to the given alignment?
assert!(WordAddr::from_usize(0xFF).is_aligned_to(2) == false);
assert!(WordAddr::from_usize(0xF0).is_aligned_to(2) == true);
Accessing this function directly from memory management code is unsupported
Sourcefn from_ptr<T>(ptr: *const T) -> Self
fn from_ptr<T>(ptr: *const T) -> Self
Construct an address from an immutable constant Rust pointer type.
Accessing this function directly from memory management code is unsupported
Sourcefn to_ptr<T>(&self) -> *const T
fn to_ptr<T>(&self) -> *const T
Deconstruct an address into an immutable constant Rust pointer type.
Accessing this function directly from memory management code is unsupported
Sourcefn to_ptr_mut<T>(&self) -> *mut T
fn to_ptr_mut<T>(&self) -> *mut T
Construct an address from a mutable constant Rust pointer type.
Accessing this function directly from memory management code is unsupported
Sourcefn zero() -> Self
fn zero() -> Self
Construct the (universal) null address.
Accessing this function directly from memory management code is unsupported
Sourcefn diff<A: Address>(&self, another: A) -> usize
fn diff<A: Address>(&self, another: A) -> usize
Compute the number of bytes before this address (exclusive) and after
another
address (inclusive).
let wa1 : WordAddr = WordAddr::from_usize(0xFF);
let wa2 : WordAddr = WordAddr::zero(); // The null address
assert!(wa1.diff(wa2) == 0xFF)
Accessing this function directly from memory management code is unsupported
Sourcefn memset(&self, val: u8, length: usize)
fn memset(&self, val: u8, length: usize)
Set the first length
bytes pointed to by this address to the byte val
.
Accessing this function directly from memory management code is unsupported
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.