Struct gdnative::core_types::Dictionary
source · [−]Expand description
A reference-counted Dictionary
of Variant
key-value pairs.
Generic methods on this type performs Variant
conversion every time. This could
be significant for complex structures. Users may convert arguments to Variant
s before
calling to avoid this behavior if necessary.
Safety
This is a reference-counted collection with “interior mutability” in Rust parlance.
To enforce that the official thread-safety guidelines are
followed this type uses the typestate pattern. The typestate Ownership
tracks
whether there is thread-local or unique access (where pretty much all operations are safe)
or whether the value might be “shared”, in which case not all operations are
safe.
Implementations
sourceimpl<Own> Dictionary<Own>where
Own: Ownership,
impl<Own> Dictionary<Own>where
Own: Ownership,
Operations allowed on all Dictionaries at any point in time.
sourcepub fn contains<K>(&self, key: K) -> boolwhere
K: OwnedToVariant + ToVariantEq,
pub fn contains<K>(&self, key: K) -> boolwhere
K: OwnedToVariant + ToVariantEq,
Returns true if the Dictionary
contains the specified key.
sourcepub fn contains_all<ArrayOws>(&self, keys: &VariantArray<ArrayOws>) -> boolwhere
ArrayOws: Ownership,
pub fn contains_all<ArrayOws>(&self, keys: &VariantArray<ArrayOws>) -> boolwhere
ArrayOws: Ownership,
Returns true if the Dictionary
has all of the keys in the given array.
sourcepub fn get<K>(&self, key: K) -> Option<Variant>where
K: OwnedToVariant + ToVariantEq,
pub fn get<K>(&self, key: K) -> Option<Variant>where
K: OwnedToVariant + ToVariantEq,
Returns a copy of the value corresponding to the key if it exists.
sourcepub fn get_or<K, D>(&self, key: K, default: D) -> Variantwhere
K: OwnedToVariant + ToVariantEq,
D: OwnedToVariant,
pub fn get_or<K, D>(&self, key: K, default: D) -> Variantwhere
K: OwnedToVariant + ToVariantEq,
D: OwnedToVariant,
Returns a copy of the value corresponding to the key, or default
if it doesn’t exist
sourcepub fn get_or_nil<K>(&self, key: K) -> Variantwhere
K: OwnedToVariant + ToVariantEq,
pub fn get_or_nil<K>(&self, key: K) -> Variantwhere
K: OwnedToVariant + ToVariantEq,
Returns a copy of the element corresponding to the key, or Nil
if it doesn’t exist.
Shorthand for self.get_or(key, Variant::nil())
.
sourcepub fn update<K, V>(&self, key: K, val: V)where
K: OwnedToVariant + ToVariantEq,
V: OwnedToVariant,
pub fn update<K, V>(&self, key: K, val: V)where
K: OwnedToVariant + ToVariantEq,
V: OwnedToVariant,
Update an existing element corresponding to the key.
Panics
Panics if the entry for key
does not exist.
sourcepub unsafe fn get_ref<K>(&self, key: K) -> &Variantwhere
K: OwnedToVariant + ToVariantEq,
pub unsafe fn get_ref<K>(&self, key: K) -> &Variantwhere
K: OwnedToVariant + ToVariantEq,
Returns a reference to the value corresponding to the key, inserting a Nil
value first if
it does not exist.
Safety
The returned reference is invalidated if the same container is mutated through another
reference, and other references may be invalidated if the entry does not already exist
(which causes this function to insert Nil
and thus possibly re-allocate).
Variant
is reference-counted and thus cheaply cloned. Consider using get
instead.
sourcepub unsafe fn get_mut_ref<K>(&self, key: K) -> &mut Variantwhere
K: OwnedToVariant + ToVariantEq,
pub unsafe fn get_mut_ref<K>(&self, key: K) -> &mut Variantwhere
K: OwnedToVariant + ToVariantEq,
Returns a mutable reference to the value corresponding to the key, inserting a Nil
value
first if it does not exist.
Safety
The returned reference is invalidated if the same container is mutated through another
reference, and other references may be invalidated if the key
does not already exist
(which causes this function to insert Nil
and thus possibly re-allocate). It is also
possible to create two mutable references to the same memory location if the same key
is provided, causing undefined behavior.
sourcepub fn to_json(&self) -> GodotString
pub fn to_json(&self) -> GodotString
Returns a GodotString of the Dictionary
.
sourcepub fn keys(&self) -> VariantArray<Unique>
pub fn keys(&self) -> VariantArray<Unique>
Returns an array of the keys in the Dictionary
.
sourcepub fn values(&self) -> VariantArray<Unique>
pub fn values(&self) -> VariantArray<Unique>
Returns an array of the values in the Dictionary
.
sourcepub fn iter(&self) -> Iter<'_, Own>
pub fn iter(&self) -> Iter<'_, Own>
Returns an iterator through all key-value pairs in the Dictionary
.
Dictionary
is reference-counted and have interior mutability in Rust parlance.
Modifying the same underlying collection while observing the safety assumptions will
not violate memory safely, but may lead to surprising behavior in the iterator.
sourcepub fn duplicate(&self) -> Dictionary<Unique>
pub fn duplicate(&self) -> Dictionary<Unique>
Create a copy of the dictionary.
This creates a new dictionary and is not a cheap reference count increment.
Operations allowed on Dictionaries that might be shared between different threads.
Create a new shared dictionary.
sourceimpl Dictionary<ThreadLocal>
impl Dictionary<ThreadLocal>
Operations allowed on Dictionaries that may only be shared on the current thread.
sourcepub fn new_thread_local() -> Dictionary<ThreadLocal>
pub fn new_thread_local() -> Dictionary<ThreadLocal>
Create a new thread-local dictionary.
sourceimpl<Own> Dictionary<Own>where
Own: NonUniqueOwnership,
impl<Own> Dictionary<Own>where
Own: NonUniqueOwnership,
Operations allowed on Dictionaries that are not unique.
sourcepub unsafe fn assume_unique(self) -> Dictionary<Unique>
pub unsafe fn assume_unique(self) -> Dictionary<Unique>
Assume that this is the only reference to this dictionary, on which operations that change the container size can be safely performed.
Safety
It isn’t thread-safe to perform operations that change the container
size from multiple threads at the same time.
Creating multiple Unique
references to the same collections, or
violating the thread-safety guidelines in non-Rust code will cause
undefined behavior.
sourceimpl<Own> Dictionary<Own>where
Own: LocalThreadOwnership,
impl<Own> Dictionary<Own>where
Own: LocalThreadOwnership,
Operations allowed on Dictionaries that can only be referenced to from the current thread.
sourcepub fn insert<K, V>(&self, key: K, val: V)where
K: OwnedToVariant + ToVariantEq,
V: OwnedToVariant,
pub fn insert<K, V>(&self, key: K, val: V)where
K: OwnedToVariant + ToVariantEq,
V: OwnedToVariant,
Inserts or updates the value of the element corresponding to the key.
sourcepub fn erase<K>(&self, key: K)where
K: OwnedToVariant + ToVariantEq,
pub fn erase<K>(&self, key: K)where
K: OwnedToVariant + ToVariantEq,
Erase a key-value pair in the Dictionary
by the specified key.
sourceimpl Dictionary<Unique>
impl Dictionary<Unique>
Operations allowed on unique Dictionaries.
sourcepub fn new() -> Dictionary<Unique>
pub fn new() -> Dictionary<Unique>
Creates an empty Dictionary
.
Put this dictionary under the “shared” access type.
sourcepub fn into_thread_local(self) -> Dictionary<ThreadLocal>
pub fn into_thread_local(self) -> Dictionary<ThreadLocal>
Put this dictionary under the “thread-local” access type.
Trait Implementations
fn coerce_from_variant(v: &Variant) -> Dictionary<Shared>
sourceimpl<Own> Debug for Dictionary<Own>where
Own: Ownership,
impl<Own> Debug for Dictionary<Own>where
Own: Ownership,
sourcefn default() -> Dictionary<Shared>
fn default() -> Dictionary<Shared>
sourceimpl Default for Dictionary<ThreadLocal>
impl Default for Dictionary<ThreadLocal>
sourcefn default() -> Dictionary<ThreadLocal>
fn default() -> Dictionary<ThreadLocal>
sourceimpl Default for Dictionary<Unique>
impl Default for Dictionary<Unique>
sourcefn default() -> Dictionary<Unique>
fn default() -> Dictionary<Unique>
sourceimpl<Own> Drop for Dictionary<Own>where
Own: Ownership,
impl<Own> Drop for Dictionary<Own>where
Own: Ownership,
sourcefn export_info(
_hint: Option<<Dictionary<Shared> as Export>::Hint>
) -> ExportInfo
fn export_info(
_hint: Option<<Dictionary<Shared> as Export>::Hint>
) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl<K, V, Own> Extend<(K, V)> for Dictionary<Own>where
Own: LocalThreadOwnership,
K: ToVariantEq + OwnedToVariant,
V: OwnedToVariant,
impl<K, V, Own> Extend<(K, V)> for Dictionary<Own>where
Own: LocalThreadOwnership,
K: ToVariantEq + OwnedToVariant,
V: OwnedToVariant,
sourcefn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)