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
impl VMHashMap
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a new empty HashMap with an initial capacity.
Sourcepub fn get<ENV>(&self, vm: &GVm<ENV>, key: Value) -> Option<Value>
pub fn get<ENV>(&self, vm: &GVm<ENV>, key: Value) -> Option<Value>
Get the value at key, requires the current VM for hashing.
Sourcepub fn insert<ENV>(
&mut self,
vm: &GVm<ENV>,
key: Value,
val: Value,
) -> Option<Value>
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).
Sourcepub fn insert_id(&mut self, id: ValHash, val: Value) -> Option<Value>
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.
Sourcepub fn contains_key<ENV>(&self, vm: &GVm<ENV>, key: Value) -> bool
pub fn contains_key<ENV>(&self, vm: &GVm<ENV>, key: Value) -> bool
Does this HashMap contain key?
Sourcepub fn remove<ENV>(&mut self, vm: &GVm<ENV>, key: Value) -> Option<Value>
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).
Sourcepub fn remove_id(&mut self, id: ValHash) -> Option<Value>
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.
Sourcepub fn iter(&self) -> VMHashMapIter<'_> ⓘ
pub fn iter(&self) -> VMHashMapIter<'_> ⓘ
Return an iterator over all the (key, value) pairs in the HashMap.
Trait Implementations§
impl BridgedType for VMHashMap
A VMHashMap
that contains a BridgedType
can be represented as a rust value.