[][src]Struct gdnative::prelude::VariantArray

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

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

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

Operations allowed on all arrays at any point in time.

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

Sets the value of the element at the given offset.

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

Returns a copy of the element at the given offset.

pub unsafe fn get_ref(&self, idx: i32) -> &Variant[src]

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.

pub unsafe fn get_mut_ref(&self, idx: i32) -> &mut Variant[src]

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) -> i32 where
    T: ToVariant
[src]

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

Returns true if the VariantArray contains no elements.

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

Returns the number of elements in the array.

pub fn find<T>(&self, what: T, from: i32) -> i32 where
    T: ToVariant
[src]

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.

pub fn contains<T>(&self, what: T) -> bool where
    T: ToVariant
[src]

Returns true if the VariantArray contains the specified value.

pub fn rfind<T>(&self, what: T, from: i32) -> i32 where
    T: ToVariant
[src]

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.

pub fn find_last<T>(&self, what: T) -> i32 where
    T: ToVariant
[src]

Searches the array in reverse order for a value. Returns its index or -1 if not found.

pub fn invert(&self)[src]

Inverts the order of the elements in the array.

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

Return a hashed i32 value representing the array contents.

pub fn sort(&self)[src]

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

Create a copy of the array.

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

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;
[src]

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.

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

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

pub fn clear(&self)[src]

Clears the array, resizing to 0.

pub fn remove(&self, idx: i32)[src]

Removes the element at idx.

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

Removed the first occurrence of val.

pub fn resize(&self, size: i32)[src]

Resizes the array, filling with Nil if necessary.

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

Appends an element at the end of the array.

pub fn pop(&self) -> Variant[src]

Removes an element at the end of the array.

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

Appends an element to the front of the array.

pub fn pop_front(&self) -> Variant[src]

Removes an element at the front of the array.

pub fn insert<T>(&self, at: i32, val: T) where
    T: OwnedToVariant
[src]

Insert a new int at a given position in the array.

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

Operations allowed on non-unique arrays.

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

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.

impl VariantArray<Unique>[src]

Operations allowed on unique arrays.

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

Creates an empty VariantArray.

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

Put this array under the "shared" access type.

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

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

impl VariantArray<Shared>[src]

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

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

Create a new shared array.

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 array, resizing to 0.

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 remove(&self, idx: i32)[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.

Removes the element at idx.

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<T>(&self, val: T) where
    T: ToVariant
[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.

Removed the first occurrence of val.

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 resize(&self, size: i32)[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.

Resizes the array, filling with Nil if necessary.

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 push<T>(&self, val: T) where
    T: 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.

Appends an element at the end of the array.

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 pop(&self) -> Variant[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.

Removes an element at the end of the array.

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 push_front<T>(&self, val: T) where
    T: 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.

Appends an element to the front of the array.

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 pop_front(&self) -> Variant[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.

Removes an element at the front of the array.

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 insert<T>(&self, at: i32, val: T) where
    T: 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.

Insert a new int at a given position in the array.

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 VariantArray<ThreadLocal>[src]

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

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

Create a new thread-local array.

Trait Implementations

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

impl Default for VariantArray<Shared>[src]

impl Default for VariantArray<ThreadLocal>[src]

impl Default for VariantArray<Unique>[src]

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

impl Export for VariantArray<Shared>[src]

type Hint = ()

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

impl<T, Access> Extend<T> for VariantArray<Access> where
    Access: LocalThreadAccess,
    T: ToVariant
[src]

impl<T> FromIterator<T> for VariantArray<Unique> where
    T: ToVariant
[src]

impl FromVariant for VariantArray<Shared>[src]

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

type Item = Variant

The type of the elements being iterated over.

type IntoIter = Iter<'a, Access>

Which kind of iterator are we turning this into?

impl IntoIterator for VariantArray<Unique>[src]

type Item = Variant

The type of the elements being iterated over.

type IntoIter = IntoIter

Which kind of iterator are we turning this into?

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

impl OwnedToVariant for VariantArray<Unique>[src]

impl ToVariant for VariantArray<Shared>[src]

Auto Trait Implementations

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

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

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

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

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