pub struct Dictionary<Own = Shared>where
    Own: Ownership,
{ /* private fields */ }
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 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 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§

source§

impl<Own> Dictionary<Own>where
    Own: Ownership,

Operations allowed on all Dictionaries at any point in time.

source

pub fn is_empty(&self) -> bool

Returns true if the Dictionary contains no elements.

source

pub fn len(&self) -> i32

Returns the number of elements in the Dictionary.

source

pub fn contains<K>(&self, key: K) -> boolwhere
    K: OwnedToVariant + ToVariantEq,

Returns true if the Dictionary contains the specified key.

source

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.

source

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.

source

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

source

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()).

source

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.

source

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.

source

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.

source

pub fn to_json(&self) -> GodotString

Returns a GodotString of the Dictionary.

source

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

Returns an array of the keys in the Dictionary.

source

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

Returns an array of the values in the Dictionary.

source

pub fn hash(&self) -> i32

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

source

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.

source

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.

source§

impl Dictionary<Shared>

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

source

pub fn new_shared() -> Dictionary<Shared>

Create a new shared dictionary.

source§

impl Dictionary<ThreadLocal>

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

source

pub fn new_thread_local() -> Dictionary<ThreadLocal>

Create a new thread-local dictionary.

source§

impl<Own> Dictionary<Own>where
    Own: NonUniqueOwnership,

Operations allowed on Dictionaries that are not unique.

source

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.

source§

impl<Own> Dictionary<Own>where
    Own: LocalThreadOwnership,

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

source

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.

source

pub fn erase<K>(&self, key: K)where
    K: OwnedToVariant + ToVariantEq,

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

source

pub fn clear(&self)

Clears the Dictionary, removing all key-value pairs.

source§

impl Dictionary<Unique>

Operations allowed on unique Dictionaries.

source

pub fn new() -> Dictionary<Unique>

Creates an empty Dictionary.

source

pub fn into_shared(self) -> Dictionary<Shared>

Put this dictionary under the “shared” access type.

source

pub fn into_thread_local(self) -> Dictionary<ThreadLocal>

Put this dictionary under the “thread-local” access type.

Trait Implementations§

source§

impl CoerceFromVariant for Dictionary<Shared>

source§

impl<Own> Debug for Dictionary<Own>where
    Own: Ownership,

source§

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

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

impl Default for Dictionary<Shared>

source§

fn default() -> Dictionary<Shared>

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

impl Default for Dictionary<ThreadLocal>

source§

fn default() -> Dictionary<ThreadLocal>

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

impl Default for Dictionary<Unique>

source§

fn default() -> Dictionary<Unique>

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

impl<Own> Drop for Dictionary<Own>where
    Own: Ownership,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Export for Dictionary<Shared>

§

type Hint = NoHint

A type-specific hint type that is valid for the type being exported. Read more
source§

fn export_info(
    _hint: Option<<Dictionary<Shared> as Export>::Hint>
) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

impl<K, V, Own> Extend<(K, V)> for Dictionary<Own>where
    Own: LocalThreadOwnership,
    K: ToVariantEq + OwnedToVariant,
    V: OwnedToVariant,

source§

fn extend<I>(&mut self, iter: I)where
    I: IntoIterator<Item = (K, V)>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<Dictionary<Unique>> for Dictionary<Shared>

source§

fn from(dict: Dictionary<Unique>) -> Dictionary<Shared>

Converts to this type from the input type.
source§

impl From<Dictionary<Unique>> for Dictionary<ThreadLocal>

source§

fn from(dict: Dictionary<Unique>) -> Dictionary<ThreadLocal>

Converts to this type from the input type.
source§

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

source§

fn from_iter<I>(iter: I) -> Dictionary<Unique>where
    I: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
source§

impl FromVariant for Dictionary<Shared>

source§

impl<'a, Own> IntoIterator for &'a Dictionary<Own>where
    Own: Ownership,

§

type Item = (Variant, Variant)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Own>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> <&'a Dictionary<Own> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Dictionary<Unique>

§

type Item = (Variant, Variant)

The type of the elements being iterated over.
§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> <Dictionary<Unique> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<Own> NewRef for Dictionary<Own>where
    Own: NonUniqueOwnership,

source§

fn new_ref(&self) -> Dictionary<Own>

Creates a new reference to the underlying object.
source§

impl OwnedToVariant for Dictionary<Unique>

source§

impl ToVariant for Dictionary<Shared>

Auto Trait Implementations§

§

impl<Own> RefUnwindSafe for Dictionary<Own>where
    Own: RefUnwindSafe,

§

impl<Own> Send for Dictionary<Own>where
    Own: Send,

§

impl<Own> Sync for Dictionary<Own>where
    Own: Sync,

§

impl<Own> Unpin for Dictionary<Own>where
    Own: Unpin,

§

impl<Own> UnwindSafe for Dictionary<Own>where
    Own: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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> OwnedToVariant for Twhere
    T: ToVariant,

source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.