[][src]Struct gdnative::prelude::Dictionary

pub struct Dictionary<Access = Shared> where
    Access: ThreadAccess
{ /* fields omitted */ }

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 Variants 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 Access 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

impl<Access> Dictionary<Access> where
    Access: ThreadAccess
[src]

Operations allowed on all Dictionaries at any point in time.

pub fn is_empty(&self) -> bool[src]

Returns true if the Dictionary contains no elements.

pub fn len(&self) -> i32[src]

Returns the number of elements in the Dictionary.

pub fn contains<K>(&self, key: K) -> bool where
    K: ToVariant + ToVariantEq
[src]

Returns true if the Dictionary contains the specified key.

pub fn contains_all<ArrAccess>(&self, keys: &VariantArray<ArrAccess>) -> bool where
    ArrAccess: ThreadAccess
[src]

Returns true if the Dictionary has all of the keys in the given array.

pub fn get<K>(&self, key: K) -> Variant where
    K: ToVariant + ToVariantEq
[src]

Returns a copy of the value corresponding to the key.

pub fn update<K, V>(&self, key: K, val: V) where
    K: ToVariant + ToVariantEq,
    V: OwnedToVariant
[src]

Update an existing element corresponding ot the key.

Panics

Panics if the entry for key does not exist.

pub unsafe fn get_ref<K>(&self, key: K) -> &Variant where
    K: ToVariant + ToVariantEq
[src]

Returns a reference to the value corresponding to the key.

Safety

The returned reference is invalidated if the same container is mutated through another reference.

Variant is reference-counted and thus cheaply cloned. Consider using get instead.

pub unsafe fn get_mut_ref<K>(&self, key: K) -> &mut Variant where
    K: ToVariant + ToVariantEq
[src]

Returns a mutable reference to the value corresponding to the key.

Safety

The returned reference is invalidated if the same container is mutated through another reference. It is possible to create two mutable references to the same memory location if the same key is provided, causing undefined behavior.

pub fn to_json(&self) -> GodotString[src]

Returns a GodotString of the Dictionary.

pub fn keys(&self) -> VariantArray<Unique>[src]

Returns an array of the keys in the Dictionary.

pub fn values(&self) -> VariantArray<Unique>[src]

Returns an array of the values in the Dictionary.

pub fn get_next(&self, key: &Variant) -> &Variant[src]

pub fn hash(&self) -> i32[src]

Return a hashed i32 value representing the dictionary's contents.

pub fn iter(&self) -> Iter<'_, Access>

Notable traits for Iter<'a, Access>

impl<'a, Access> Iterator for Iter<'a, Access> where
    Access: ThreadAccess
type Item = (Variant, Variant);
[src]

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.

pub fn duplicate(&self) -> Dictionary<Unique>[src]

Create a copy of the dictionary.

This creates a new dictionary and is not a cheap reference count increment.

impl Dictionary<Shared>[src]

Operations allowed on Dictionaries that might be shared between different threads.

pub fn new_shared() -> Dictionary<Shared>[src]

Create a new shared dictionary.

pub unsafe fn insert<K, V>(&self, key: K, val: V) where
    K: OwnedToVariant + ToVariantEq,
    V: OwnedToVariant
[src]

👎 Deprecated:

Care should be used when mutating shared variant collections. Prefer ThreadLocal or Unique collections unless you're absolutely sure that you want this. You may use assume_unique to convert this to a Unique collection if you are sure that this is in fact the only reference.

Inserts or updates the value of the element corresponding to the key.

Safety

Generally, it's not recommended to mutate variant collections that may be shared. Prefer ThreadLocal or Unique collections instead. If you're sure that the current reference is unique, you may use assume_unique to convert it to a Unique collection. You may subsequently use into_thread_local to convert it to a ThreadLocal one.

It is only safe to perform operations that may allocate on a shared collection when no other thread may access the underlying collection during the call.

pub unsafe fn erase<K>(&self, key: K) where
    K: ToVariant + ToVariantEq
[src]

👎 Deprecated:

Care should be used when mutating shared variant collections. Prefer ThreadLocal or Unique collections unless you're absolutely sure that you want this. You may use assume_unique to convert this to a Unique collection if you are sure that this is in fact the only reference.

Erase a key-value pair in the Dictionary by the specified key.

Safety

Generally, it's not recommended to mutate variant collections that may be shared. Prefer ThreadLocal or Unique collections instead. If you're sure that the current reference is unique, you may use assume_unique to convert it to a Unique collection. You may subsequently use into_thread_local to convert it to a ThreadLocal one.

It is only safe to perform operations that may allocate on a shared collection when no other thread may access the underlying collection during the call.

pub unsafe fn clear(&self)[src]

👎 Deprecated:

Care should be used when mutating shared variant collections. Prefer ThreadLocal or Unique collections unless you're absolutely sure that you want this. You may use assume_unique to convert this to a Unique collection if you are sure that this is in fact the only reference.

Clears the Dictionary, removing all key-value pairs.

Safety

Generally, it's not recommended to mutate variant collections that may be shared. Prefer ThreadLocal or Unique collections instead. If you're sure that the current reference is unique, you may use assume_unique to convert it to a Unique collection. You may subsequently use into_thread_local to convert it to a ThreadLocal one.

It is only safe to perform operations that may allocate on a shared collection when no other thread may access the underlying collection during the call.

impl Dictionary<ThreadLocal>[src]

Operations allowed on Dictionaries that may only be shared on the current thread.

pub fn new_thread_local() -> Dictionary<ThreadLocal>[src]

Create a new thread-local dictionary.

impl<Access> Dictionary<Access> where
    Access: NonUniqueThreadAccess
[src]

Operations allowed on Dictionaries that are not unique.

pub unsafe fn assume_unique(self) -> Dictionary<Unique>[src]

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.

impl<Access> Dictionary<Access> where
    Access: LocalThreadAccess
[src]

Operations allowed on Dictionaries that can only be referenced to from the current thread.

pub fn insert<K, V>(&self, key: K, val: V) where
    K: OwnedToVariant + ToVariantEq,
    V: OwnedToVariant
[src]

Inserts or updates the value of the element corresponding to the key.

pub fn erase<K>(&self, key: K) where
    K: ToVariant + ToVariantEq
[src]

Erase a key-value pair in the Dictionary by the specified key.

pub fn clear(&self)[src]

Clears the Dictionary, removing all key-value pairs.

impl Dictionary<Unique>[src]

Operations allowed on unique Dictionaries.

pub fn new() -> Dictionary<Unique>[src]

Creates an empty Dictionary.

pub fn into_shared(self) -> Dictionary<Shared>[src]

Put this dictionary under the "shared" access type.

pub fn into_thread_local(self) -> Dictionary<ThreadLocal>[src]

Put this dictionary under the "thread-local" access type.

Trait Implementations

impl<Access> Debug for Dictionary<Access> where
    Access: ThreadAccess
[src]

impl Default for Dictionary<Unique>[src]

impl Default for Dictionary<ThreadLocal>[src]

impl Default for Dictionary<Shared>[src]

impl<Access> Drop for Dictionary<Access> where
    Access: ThreadAccess
[src]

impl Export for Dictionary<Shared>[src]

type Hint = ()

A type-specific hint type that is valid for the type being exported.

impl<K, V, Access> Extend<(K, V)> for Dictionary<Access> where
    Access: LocalThreadAccess,
    K: ToVariantEq + OwnedToVariant,
    V: OwnedToVariant
[src]

impl From<Dictionary<Unique>> for Dictionary<ThreadLocal>[src]

impl From<Dictionary<Unique>> for Dictionary<Shared>[src]

impl<K, V> FromIterator<(K, V)> for Dictionary<Unique> where
    K: ToVariantEq + OwnedToVariant,
    V: OwnedToVariant
[src]

impl FromVariant for Dictionary<Shared>[src]

impl IntoIterator for Dictionary<Unique>[src]

type Item = (Variant, Variant)

The type of the elements being iterated over.

type IntoIter = IntoIter

Which kind of iterator are we turning this into?

impl<'a, Access> IntoIterator for &'a Dictionary<Access> where
    Access: ThreadAccess
[src]

type Item = (Variant, Variant)

The type of the elements being iterated over.

type IntoIter = Iter<'a, Access>

Which kind of iterator are we turning this into?

impl<Access> NewRef for Dictionary<Access> where
    Access: NonUniqueThreadAccess
[src]

impl OwnedToVariant for Dictionary<Unique>[src]

impl ToVariant for Dictionary<Shared>[src]

Auto Trait Implementations

impl<Access> RefUnwindSafe for Dictionary<Access> where
    Access: RefUnwindSafe

impl<Access> Send for Dictionary<Access> where
    Access: Send

impl<Access> Sync for Dictionary<Access> where
    Access: Sync

impl<Access> Unpin for Dictionary<Access> where
    Access: Unpin

impl<Access> UnwindSafe for Dictionary<Access> where
    Access: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> OwnedToVariant for T where
    T: ToVariant
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.