Struct koto_runtime::KMap

source ·
pub struct KMap { /* private fields */ }
Expand description

The core hashmap value type used in Koto, containing a ValueMap and a MetaMap

Implementations§

source§

impl KMap

source

pub fn new() -> Self

Creates an empty KMap

source

pub fn with_type(type_name: &str) -> Self

Creates an empty KMap, with a MetaMap containing the given @type string

source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty KMap with the given capacity

source

pub fn with_data(data: ValueMap) -> Self

Creates a KMap initialized with the provided data

source

pub fn with_contents(data: ValueMap, meta: Option<MetaMap>) -> Self

Creates a KMap initialized with the provided data and meta map

source

pub fn from_data_and_meta_maps(data: &Self, meta: &Self) -> Self

Makes a KMap taking the data map from the first arg, and the meta map from the second

source

pub fn data(&self) -> Borrow<'_, ValueMap>

Provides a reference to the data map

source

pub fn data_mut(&self) -> BorrowMut<'_, ValueMap>

Provides a mutable reference to the data map

source

pub fn meta_map(&self) -> Option<&PtrMut<MetaMap>>

Provides a reference to the KMap’s meta map

This is returned as a reference to the meta map’s PtrMut to allow for cloning.

source

pub fn set_meta_map(&mut self, meta: Option<PtrMut<MetaMap>>)

Sets the KMap’s meta map

Note that this change isn’t shared with maps that share the same data.

source

pub fn contains_meta_key(&self, key: &MetaKey) -> bool

Returns true if the meta map contains an entry with the given key

source

pub fn get<K>(&self, key: &K) -> Option<KValue>
where K: Hash + Equivalent<ValueKey> + ?Sized,

Returns a clone of the data value corresponding to the given key

source

pub fn get_meta_value(&self, key: &MetaKey) -> Option<KValue>

Returns a clone of the meta value corresponding to the given key

source

pub fn insert(&self, key: impl Into<ValueKey>, value: impl Into<KValue>)

Insert an entry into the KMap’s data

source

pub fn insert_meta(&mut self, key: MetaKey, value: KValue)

Inserts a value into the meta map, initializing the meta map if it doesn’t yet exist

source

pub fn add_fn(&self, id: &str, f: impl KotoFunction)

Adds a function to the KMap’s data map

source

pub fn len(&self) -> usize

Returns the number of entries in the KMap’s data map

Note that this doesn’t include entries in the meta map.

source

pub fn is_empty(&self) -> bool

Returns true if the KMap’s data map contains no entries

Note that this doesn’t take entries in the meta map into account.

source

pub fn clear(&mut self)

Removes all contents from the data map, and removes the meta map

source

pub fn is_same_instance(&self, other: &Self) -> bool

Returns true if the provided KMap occupies the same memory address

source

pub fn display(&self, ctx: &mut DisplayContext<'_>) -> Result<()>

Renders the map to the provided display context

Trait Implementations§

source§

impl Clone for KMap

source§

fn clone(&self) -> KMap

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 Default for KMap

source§

fn default() -> KMap

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

impl From<KMap> for KValue

source§

fn from(value: KMap) -> Self

Converts to this type from the input type.
source§

impl From<ValueMap> for KMap

source§

fn from(value: ValueMap) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for KMap

§

impl !RefUnwindSafe for KMap

§

impl Send for KMap

§

impl Sync for KMap

§

impl Unpin for KMap

§

impl !UnwindSafe for KMap

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> 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> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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,

§

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>,

§

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>,

§

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.