Struct gdnative::core_types::VariantArray
source · Expand description
A reference-counted Variant
vector. Godot’s generic array data type.
Negative indices can be used to count from the right.
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§
source§impl<Own> VariantArray<Own>where
Own: Ownership,
impl<Own> VariantArray<Own>where
Own: Ownership,
Operations allowed on all arrays at any point in time.
sourcepub fn set<T>(&self, idx: i32, val: T)where
T: OwnedToVariant,
pub fn set<T>(&self, idx: i32, val: T)where
T: OwnedToVariant,
Sets the value of the element at the given offset.
sourcepub unsafe fn get_ref(&self, idx: i32) -> &Variant
pub unsafe fn get_ref(&self, idx: i32) -> &Variant
Returns a reference to the element at the given offset.
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.
sourcepub unsafe fn get_mut_ref(&self, idx: i32) -> &mut Variant
pub unsafe fn get_mut_ref(&self, idx: i32) -> &mut Variant
Returns a mutable reference to the element at the given offset.
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 idx
is provided, causing undefined behavior.
pub fn count<T>(&self, val: T) -> i32where
T: ToVariant,
sourcepub fn find<T>(&self, what: T, from: i32) -> i32where
T: ToVariant,
pub fn find<T>(&self, what: T, from: i32) -> i32where
T: ToVariant,
Searches the array for a value and returns its index.
Pass an initial search index as the second argument.
Returns -1
if value is not found.
sourcepub fn contains<T>(&self, what: T) -> boolwhere
T: ToVariant,
pub fn contains<T>(&self, what: T) -> boolwhere
T: ToVariant,
Returns true if the VariantArray
contains the specified value.
sourcepub fn rfind<T>(&self, what: T, from: i32) -> i32where
T: ToVariant,
pub fn rfind<T>(&self, what: T, from: i32) -> i32where
T: ToVariant,
Searches the array in reverse order. Pass an initial search index as the second argument. If negative, the start index is considered relative to the end of the array.
sourcepub fn find_last<T>(&self, what: T) -> i32where
T: ToVariant,
pub fn find_last<T>(&self, what: T) -> i32where
T: ToVariant,
Searches the array in reverse order for a value.
Returns its index or -1
if not found.
pub fn sort(&self)
sourcepub fn duplicate(&self) -> VariantArray<Unique>
pub fn duplicate(&self) -> VariantArray<Unique>
Create a copy of the array.
This creates a new array and is not a cheap reference count increment.
sourcepub fn duplicate_deep(&self) -> VariantArray<Unique>
pub fn duplicate_deep(&self) -> VariantArray<Unique>
Create a deep copy of the array.
This creates a new array and is not a cheap reference count increment.
sourcepub fn iter(&self) -> Iter<'_, Own>
pub fn iter(&self) -> Iter<'_, Own>
Returns an iterator through all values in the VariantArray
.
VariantArray
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§impl<Own> VariantArray<Own>where
Own: LocalThreadOwnership,
impl<Own> VariantArray<Own>where
Own: LocalThreadOwnership,
Operations allowed on Dictionaries that can only be referenced to from the current thread.
sourcepub fn push<T>(&self, val: T)where
T: OwnedToVariant,
pub fn push<T>(&self, val: T)where
T: OwnedToVariant,
Appends an element at the end of the array.
sourcepub fn push_front<T>(&self, val: T)where
T: OwnedToVariant,
pub fn push_front<T>(&self, val: T)where
T: OwnedToVariant,
Appends an element to the front of the array.
sourcepub fn insert<T>(&self, at: i32, val: T)where
T: OwnedToVariant,
pub fn insert<T>(&self, at: i32, val: T)where
T: OwnedToVariant,
Insert a new int at a given position in the array.
source§impl<Own> VariantArray<Own>where
Own: NonUniqueOwnership,
impl<Own> VariantArray<Own>where
Own: NonUniqueOwnership,
Operations allowed on non-unique arrays.
sourcepub unsafe fn assume_unique(self) -> VariantArray<Unique>
pub unsafe fn assume_unique(self) -> VariantArray<Unique>
Assume that this is the only reference to this array, 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 VariantArray<Unique>
impl VariantArray<Unique>
Operations allowed on unique arrays.
sourcepub fn new() -> VariantArray<Unique>
pub fn new() -> VariantArray<Unique>
Creates an empty VariantArray
.
Put this array under the “shared” access type.
sourcepub fn into_thread_local(self) -> VariantArray<ThreadLocal>
pub fn into_thread_local(self) -> VariantArray<ThreadLocal>
Put this array under the “thread-local” access type.
Operations allowed on arrays that might be shared between different threads.
Create a new shared array.
source§impl VariantArray<ThreadLocal>
impl VariantArray<ThreadLocal>
Operations allowed on Dictionaries that may only be shared on the current thread.
sourcepub fn new_thread_local() -> VariantArray<ThreadLocal>
pub fn new_thread_local() -> VariantArray<ThreadLocal>
Create a new thread-local array.
Trait Implementations§
fn coerce_from_variant(v: &Variant) -> VariantArray<Shared>
source§impl<Own> Debug for VariantArray<Own>where
Own: Ownership,
impl<Own> Debug for VariantArray<Own>where
Own: Ownership,
source§impl Default for VariantArray<ThreadLocal>
impl Default for VariantArray<ThreadLocal>
source§fn default() -> VariantArray<ThreadLocal>
fn default() -> VariantArray<ThreadLocal>
source§impl Default for VariantArray<Unique>
impl Default for VariantArray<Unique>
source§impl<Own> Drop for VariantArray<Own>where
Own: Ownership,
impl<Own> Drop for VariantArray<Own>where
Own: Ownership,
§type Hint = ArrayHint
type Hint = ArrayHint
source§fn export_info(
hint: Option<<VariantArray<Shared> as Export>::Hint>
) -> ExportInfo
fn export_info(
hint: Option<<VariantArray<Shared> as Export>::Hint>
) -> ExportInfo
ExportInfo
given an optional typed hint.source§impl<T, Own> Extend<T> for VariantArray<Own>where
T: ToVariant,
Own: LocalThreadOwnership,
impl<T, Own> Extend<T> for VariantArray<Own>where
T: ToVariant,
Own: LocalThreadOwnership,
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)