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

source§

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

Operations allowed on all arrays at any point in time.

source

pub fn set<T>(&self, idx: i32, val: T)where
    T: OwnedToVariant,

Sets the value of the element at the given offset.

source

pub fn get(&self, idx: i32) -> Variant

Returns a copy of the element at the given offset.

source

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.

source

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.

source

pub fn count<T>(&self, val: T) -> i32where
    T: ToVariant,

source

pub fn is_empty(&self) -> bool

Returns true if the VariantArray contains no elements.

source

pub fn len(&self) -> i32

Returns the number of elements in the array.

source

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.

source

pub fn contains<T>(&self, what: T) -> boolwhere
    T: ToVariant,

Returns true if the VariantArray contains the specified value.

source

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.

source

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.

source

pub fn invert(&self)

Inverts the order of the elements in the array.

source

pub fn hash(&self) -> i32

Return a hashed i32 value representing the array contents.

source

pub fn sort(&self)

source

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.

source

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.

source

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,

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

source

pub fn clear(&self)

Clears the array, resizing to 0.

source

pub fn remove(&self, idx: i32)

Removes the element at idx.

source

pub fn erase<T>(&self, val: T)where
    T: ToVariant,

Removed the first occurrence of val.

source

pub fn resize(&self, size: i32)

Resizes the array, filling with Nil if necessary.

source

pub fn push<T>(&self, val: T)where
    T: OwnedToVariant,

Appends an element at the end of the array.

source

pub fn pop(&self) -> Variant

Removes an element at the end of the array.

source

pub fn push_front<T>(&self, val: T)where
    T: OwnedToVariant,

Appends an element to the front of the array.

source

pub fn pop_front(&self) -> Variant

Removes an element at the front of the array.

source

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,

Operations allowed on non-unique arrays.

source

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>

Operations allowed on unique arrays.

source

pub fn new() -> VariantArray<Unique>

Creates an empty VariantArray.

source

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

Put this array under the “shared” access type.

source

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

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

source§

impl VariantArray<Shared>

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

source

pub fn new_shared() -> VariantArray<Shared>

Create a new shared array.

source§

impl VariantArray<ThreadLocal>

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

source

pub fn new_thread_local() -> VariantArray<ThreadLocal>

Create a new thread-local array.

Trait Implementations§

source§

impl CoerceFromVariant for VariantArray<Shared>

source§

impl<Own> Debug for VariantArray<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 VariantArray<Shared>

source§

fn default() -> VariantArray<Shared>

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

impl Default for VariantArray<ThreadLocal>

source§

fn default() -> VariantArray<ThreadLocal>

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

impl Default for VariantArray<Unique>

source§

fn default() -> VariantArray<Unique>

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

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

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Export for VariantArray<Shared>

§

type Hint = ArrayHint

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

fn export_info(
    hint: Option<<VariantArray<Shared> as Export>::Hint>
) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

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>,

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<T> FromIterator<T> for VariantArray<Unique>where
    T: ToVariant,

source§

fn from_iter<I>(iter: I) -> VariantArray<Unique>where
    I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
source§

impl FromVariant for VariantArray<Shared>

source§

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

§

type Item = 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 VariantArray<Own> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for VariantArray<Unique>

§

type Item = 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) -> <VariantArray<Unique> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

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

source§

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

Creates a new reference to the underlying object.
source§

impl OwnedToVariant for VariantArray<Unique>

source§

impl ToVariant for VariantArray<Shared>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<Own> UnwindSafe for VariantArray<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.