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
impl Memory
Sourcepub fn with_capacity(size: usize) -> Memory
pub fn with_capacity(size: usize) -> Memory
Create a new block of memory with a given capacity
Sourcepub fn write(&mut self, symbol: &Symbol, data: Data)
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.
Sourcepub fn read_untyped(&self, symbol: &Symbol) -> Result<&dyn CloneableAny, String>
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.
Sourcepub fn read_typed<T: CloneableAny + 'static>(
&self,
symbol: &Symbol,
) -> Result<&T, String>
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.
Sourcepub fn copy(&mut self, source: &Symbol, dest: &Symbol) -> Result<(), String>
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.
Trait Implementations§
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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.