Memory

Struct Memory 

Source
pub struct Memory(/* private fields */);
Expand description

Memory is what actually handles reading and writing from the symbol table.

It wraps a HashMap<Symbol, Data> and implements basic memory operations over that, including both typed and untyped reading, writing, and copying.

Implementations§

Source§

impl Memory

Source

pub fn new() -> Memory

Create a new block of memory

Source

pub fn with_capacity(size: usize) -> Memory

Create a new block of memory with a given capacity

Source

pub fn write(&mut self, symbol: &Symbol, data: Data)

Write the given data to the symbol. If the symbol does not already exist, create it.

Returns nothing and should never be able to fail, since any Symbol can we written to, even if it is undefined.

Source

pub fn read_untyped(&self, symbol: &Symbol) -> Result<&dyn CloneableAny, String>

Read from the given symbol, returning an untyped CloneableAny.

If the symbol does not exist, return an error due to trying to read an undefined symbol.

Source

pub fn read_typed<T: CloneableAny + 'static>( &self, symbol: &Symbol, ) -> Result<&T, String>

Read from the given symbol, expecting a specific type. Guaranteed to return that type or error.

If the symbol does not exist, return an error due to trying to read an undefined symbol. If the symbol does exist, but is not of the expected type, return an error.

Source

pub fn copy(&mut self, source: &Symbol, dest: &Symbol) -> Result<(), String>

Copy the data from source to dest. If dest doesn’t exist yet, create it.

If the source doesn’t exist, return an error.

While this could arguably be implented at the instruction level, having this be a memory level operation may be good for operations besides just copying.

Source

pub fn dump(&self) -> HashMap<Symbol, Data>

Get an iterator over all of the symbols currently in memory. Useful for debugging purposes.

Trait Implementations§

Source§

impl Clone for Memory

Source§

fn clone(&self) -> Memory

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for Memory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Memory

§

impl !RefUnwindSafe for Memory

§

impl !Send for Memory

§

impl !Sync for Memory

§

impl Unpin for Memory

§

impl !UnwindSafe for Memory

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> 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
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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.
Source§

impl<T> CloneableAny for T
where T: 'static + Clone,