[−][src]Struct gdnative::prelude::Dictionary
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 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]
Access: ThreadAccess,
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]
K: ToVariant + ToVariantEq,
Returns true if the Dictionary
contains the specified key.
pub fn contains_all<ArrAccess>(&self, keys: &VariantArray<ArrAccess>) -> bool where
ArrAccess: ThreadAccess,
[src]
ArrAccess: ThreadAccess,
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]
K: ToVariant + ToVariantEq,
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]
K: ToVariant + ToVariantEq,
V: OwnedToVariant,
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]
K: ToVariant + ToVariantEq,
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]
K: ToVariant + ToVariantEq,
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>ⓘ
[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]
K: OwnedToVariant + ToVariantEq,
V: OwnedToVariant,
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]
K: ToVariant + ToVariantEq,
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]
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]
Access: NonUniqueThreadAccess,
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]
Access: LocalThreadAccess,
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]
K: OwnedToVariant + ToVariantEq,
V: OwnedToVariant,
Inserts or updates the value of the element corresponding to the key.
pub fn erase<K>(&self, key: K) where
K: ToVariant + ToVariantEq,
[src]
K: ToVariant + ToVariantEq,
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]
Access: ThreadAccess,
impl Default for Dictionary<Unique>
[src]
fn default() -> Dictionary<Unique>
[src]
impl Default for Dictionary<ThreadLocal>
[src]
fn default() -> Dictionary<ThreadLocal>
[src]
impl Default for Dictionary<Shared>
[src]
fn default() -> Dictionary<Shared>
[src]
impl<Access> Drop for Dictionary<Access> where
Access: ThreadAccess,
[src]
Access: ThreadAccess,
impl Export for Dictionary<Shared>
[src]
type Hint = ()
A type-specific hint type that is valid for the type being exported.
fn export_info(
_hint: Option<<Dictionary<Shared> as Export>::Hint>
) -> ExportInfo
[src]
_hint: Option<<Dictionary<Shared> as Export>::Hint>
) -> ExportInfo
impl<K, V, Access> Extend<(K, V)> for Dictionary<Access> where
Access: LocalThreadAccess,
K: ToVariantEq + OwnedToVariant,
V: OwnedToVariant,
[src]
Access: LocalThreadAccess,
K: ToVariantEq + OwnedToVariant,
V: OwnedToVariant,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl From<Dictionary<Unique>> for Dictionary<ThreadLocal>
[src]
fn from(dict: Dictionary<Unique>) -> Dictionary<ThreadLocal>
[src]
impl From<Dictionary<Unique>> for Dictionary<Shared>
[src]
fn from(dict: Dictionary<Unique>) -> Dictionary<Shared>
[src]
impl<K, V> FromIterator<(K, V)> for Dictionary<Unique> where
K: ToVariantEq + OwnedToVariant,
V: OwnedToVariant,
[src]
K: ToVariantEq + OwnedToVariant,
V: OwnedToVariant,
fn from_iter<I>(iter: I) -> Dictionary<Unique> where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
impl FromVariant for Dictionary<Shared>
[src]
fn from_variant(
variant: &Variant
) -> Result<Dictionary<Shared>, FromVariantError>
[src]
variant: &Variant
) -> Result<Dictionary<Shared>, FromVariantError>
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?
fn into_iter(self) -> <Dictionary<Unique> as IntoIterator>::IntoIter
[src]
impl<'a, Access> IntoIterator for &'a Dictionary<Access> where
Access: ThreadAccess,
[src]
Access: ThreadAccess,
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?
fn into_iter(self) -> <&'a Dictionary<Access> as IntoIterator>::IntoIter
[src]
impl<Access> NewRef for Dictionary<Access> where
Access: NonUniqueThreadAccess,
[src]
Access: NonUniqueThreadAccess,
fn new_ref(&self) -> Dictionary<Access>
[src]
impl OwnedToVariant for Dictionary<Unique>
[src]
fn owned_to_variant(self) -> Variant
[src]
impl ToVariant for Dictionary<Shared>
[src]
fn to_variant(&self) -> Variant
[src]
Auto Trait Implementations
impl<Access> RefUnwindSafe for Dictionary<Access> where
Access: RefUnwindSafe,
Access: RefUnwindSafe,
impl<Access> Send for Dictionary<Access> where
Access: Send,
Access: Send,
impl<Access> Sync for Dictionary<Access> where
Access: Sync,
Access: Sync,
impl<Access> Unpin for Dictionary<Access> where
Access: Unpin,
Access: Unpin,
impl<Access> UnwindSafe for Dictionary<Access> where
Access: UnwindSafe,
Access: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T> OwnedToVariant for T where
T: ToVariant,
[src]
T: ToVariant,
fn owned_to_variant(self) -> Variant
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,