pub struct PoolArray<T>where
    T: PoolElement,
{ /* private fields */ }
Expand description

A reference-counted CoW typed vector using Godot’s pool allocator, generic over possible element types.

PoolArray unifies all the different Pool*Array types exported by Godot. It can be used in exported Rust methods as parameter and return types, as well as in exported properties. However, it is limited to the element types, for which a Pool*Array exists in GDScript, i.e. it cannot contain user-defined types. If you need other types, look into VariantArray or directly use Vec<T> for type safety.

This type is CoW (copy-on-write). The Clone implementation of this type creates a new reference without copying the contents.

If you need to read elements, e.g. for iteration or conversion to another collection, the read() method provides a view that dereferences to &[T]. Analogously, write() provides a writable view that dereferences to &mut [T].

For element mutations, it’s usually recommended to do process them in batch using write() or the append() methods, as opposed to push() or set(), because the latter ones trigger CoW behavior each time they are called.

Implementations

Creates an empty array.

Creates from a VariantArray by making a best effort to convert each variant.

Creates a PoolArray moving elements from src.

If your source type isn’t precisely a Vec<T>, keep in mind that PoolElement implements the FromIterator trait, which allows it to be constructed from iterators, typically through collect().

For example:

// Int32Array is a type alias for PoolArray<i32>
use gdnative::core_types::Int32Array;

// Collect from range
let arr = (0..4).collect::<Int32Array>();

// Type conversion
let vec: Vec<u32> = vec![1, 1, 2, 3, 5]; // note: unsigned
let arr = vec.iter().map(|&e| e as i32).collect::<Int32Array>();

Copies all elements to a Vec, leaving this instance untouched.

Equivalent to self.read().to_vec(). Only use this if your destination type is precisely a Vec<T>. Otherwise, call read() which can be used as a slice.

Appends an element to the end of the array.

Calling push() triggers copy-on-write behavior. To insert a large number of elements, consider using append(), resize() or write().

Appends an element to the end of the array by reference.

Calling push_ref() triggers copy-on-write behavior. To insert a large number of elements, consider using append(), resize() or write().

Copies and appends all values in src to the end of the array.

Moves all the elements from src into self, leaving src empty.

Panics

If the resulting length would not fit in i32.

Inserts an element at the given offset and returns true if successful.

Inserts an element by reference at the given offset and returns true if successful.

Inverts the order of the elements in the array.

Removes an element at the given offset.

Changes the size of the array, possibly removing elements or pushing default values.

Returns a copy of the element at the given offset.

Sets the value of the element at the given offset.

Sets the value of the element at the given offset by reference.

Returns the number of elements in the array.

Returns true if the container is empty.

Returns a scoped read-only view into this array.

The returned read guard implements Deref with target type [T], i.e. can be dereferenced to &[T]. This means all non-mutating (&self) slice methods can be used, see here.

Returns a scoped read-write view into this array. This triggers CoW once per lock, instead of once each mutation.

The returned write guard implements DerefMut with target type [T], i.e. can be dereferenced to &mut [T]. This means all mutating and read-only slice methods can be used, see here.

Creates a new PoolArray by copying from src.

Equivalent to a new object created with new(), followed by a subsequent append_slice().

Panics

If the length of src does not fit in i32.

Copies and appends all values in src to the end of the array.

Panics

If the resulting length would not fit in i32.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Executes the destructor for this type. Read more
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more

Creates a new reference to this reference-counted instance.

This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.