slvm::heap::vm_hashmap

Struct VMHashMap

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

Wrapper class for a HashMap<Value, Value>. We need this because we want String and StringConst to hash to the same value (what a script user will expect) and that requires a VM so can not just implement Hash on Value (will not have access to a VM).

Implementations§

Source§

impl VMHashMap

Source

pub fn new() -> Self

Create a new empty HashMap.

Source

pub fn with_capacity(cap: usize) -> Self

Create a new empty HashMap with an initial capacity.

Source

pub fn get<ENV>(&self, vm: &GVm<ENV>, key: Value) -> Option<Value>

Get the value at key, requires the current VM for hashing.

Source

pub fn insert<ENV>( &mut self, vm: &GVm<ENV>, key: Value, val: Value, ) -> Option<Value>

Insert the value at key, requires the current VM for hashing. Returns the old value at key if it exists (None otherwise).

Source

pub fn insert_id(&mut self, id: ValHash, val: Value) -> Option<Value>

Insert val at the key id provided. This allows calling code to pre-generate the ValHash. This is a borrow checker workaround.

Source

pub fn len(&self) -> usize

Number of items in the HashMap.

Source

pub fn is_empty(&self) -> bool

Is this HashMap empty?

Source

pub fn contains_key<ENV>(&self, vm: &GVm<ENV>, key: Value) -> bool

Does this HashMap contain key?

Source

pub fn clear(&mut self)

Clear (remove all key/values) from the HashMap.

Source

pub fn remove<ENV>(&mut self, vm: &GVm<ENV>, key: Value) -> Option<Value>

Remove key from the HashMap. Return the old value if it existed (None otherwise).

Source

pub fn remove_id(&mut self, id: ValHash) -> Option<Value>

Remove the key from HashMap (like remove) except caller pre-generates the ValHash. Used to work around the borrow checker.

Source

pub fn keys(&self) -> VMMapKeys<'_>

Returns an iterator over all the keys in the HashMap.

Source

pub fn iter(&self) -> VMHashMapIter<'_>

Return an iterator over all the (key, value) pairs in the HashMap.

Trait Implementations§

Source§

impl Clone for VMHashMap

Source§

fn clone(&self) -> VMHashMap

Returns a copy 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 Debug for VMHashMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VMHashMap

Source§

fn default() -> Self

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

impl BridgedType for VMHashMap

A VMHashMap that contains a BridgedType can be represented as a rust value.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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.