Skip to main content

Memory

Struct Memory 

Source
pub struct Memory { /* private fields */ }
Expand description

Sparse, BCT-backed guest memory.

Implementations§

Source§

impl Memory

Source

pub fn new() -> Self

Empty memory. Every address reads as uninitialised.

Source

pub fn pages_allocated(&self) -> usize

How many pages are currently allocated. For tests and diagnostics.

Source

pub fn is_aligned(addr: Word) -> bool

True when addr is word-aligned. Equivalent to testing whether the low trit is zero. Applies at every width, since everything aligns to the word (D-14).

Source

pub fn read_tryte(&self, addr: Word) -> Result<Tryte, MemoryError>

Reads one tryte. Errors if it was never written.

Source

pub fn write_tryte( &mut self, addr: Word, value: Tryte, ) -> Result<(), MemoryError>

Writes one tryte, allocating its page if needed.

Source

pub fn is_initialised(&self, addr: Word) -> bool

True when this address holds a value that was actually written.

Source

pub fn read_word(&self, addr: Word) -> Result<Word, MemoryError>

Reads a word: three trytes, least significant first.

Requires word alignment. The tryte at addr holds trits 0..9, the next holds 9..18, and the last holds 18..27, so the weights are 3^0, 3^9 and 3^18.

Source

pub fn write_word(&mut self, addr: Word, value: Word) -> Result<(), MemoryError>

Writes a word: three trytes, least significant first.

Source

pub fn read_double(&self, addr: Word) -> Result<DoubleWord, MemoryError>

Reads a double word: six trytes, least significant first.

Aligned to the word rather than to its own six trytes. Six-tryte alignment would require testing addr mod 6 == 0, which in base 3 means checking that the low trit is zero and the digit sum is even, a 27-trit reduction rather than a single trit test (D-14).

Source

pub fn write_double( &mut self, addr: Word, value: DoubleWord, ) -> Result<(), MemoryError>

Writes a double word: six trytes, least significant first.

Trait Implementations§

Source§

impl Addressable for Memory

Source§

fn read_tryte(&mut self, addr: Word) -> Result<Tryte, MemoryError>

Reads one tryte.
Source§

fn write_tryte(&mut self, addr: Word, value: Tryte) -> Result<(), MemoryError>

Writes one tryte.
Source§

fn read_word(&mut self, addr: Word) -> Result<Word, MemoryError>

Reads a word: three trytes, least significant first.
Source§

fn write_word(&mut self, addr: Word, value: Word) -> Result<(), MemoryError>

Writes a word: three trytes, least significant first.
Source§

fn is_privileged(&self, _addr: Word) -> bool

True if reaching addr should require supervisor privilege. Read more
Source§

fn interrupts(&self) -> Word

Which interrupt sources are asserting, one trit per source. Read more
Source§

impl Default for Memory

Source§

fn default() -> Memory

Returns the “default value” for a type. 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
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, 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.