Struct gdnative::core_types::PoolArray
source · [−]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
sourceimpl<T> PoolArray<T>where
T: PoolElement,
impl<T> PoolArray<T>where
T: PoolElement,
sourcepub fn from_variant_array(array: &VariantArray<Shared>) -> PoolArray<T>
pub fn from_variant_array(array: &VariantArray<Shared>) -> PoolArray<T>
Creates from a VariantArray
by making a best effort to convert each variant.
sourcepub fn from_vec(src: Vec<T, Global>) -> PoolArray<T>
pub fn from_vec(src: Vec<T, Global>) -> PoolArray<T>
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>();
sourcepub fn to_vec(&self) -> Vec<T, Global>where
T: Clone,
pub fn to_vec(&self) -> Vec<T, Global>where
T: Clone,
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.
sourcepub fn append(&mut self, src: &PoolArray<T>)
pub fn append(&mut self, src: &PoolArray<T>)
Copies and appends all values in src
to the end of the array.
sourcepub fn append_vec(&mut self, src: &mut Vec<T, Global>)
pub fn append_vec(&mut self, src: &mut Vec<T, Global>)
Moves all the elements from src
into self
, leaving src
empty.
Panics
If the resulting length would not fit in i32
.
sourcepub fn insert(&mut self, offset: i32, val: T) -> bool
pub fn insert(&mut self, offset: i32, val: T) -> bool
Inserts an element at the given offset and returns true
if successful.
sourcepub fn insert_ref(&mut self, offset: i32, val: &T) -> bool
pub fn insert_ref(&mut self, offset: i32, val: &T) -> bool
Inserts an element by reference at the given offset and returns true
if successful.
sourcepub fn resize(&mut self, size: i32)
pub fn resize(&mut self, size: i32)
Changes the size of the array, possibly removing elements or pushing default values.
sourcepub fn set_ref(&mut self, idx: i32, val: &T)
pub fn set_ref(&mut self, idx: i32, val: &T)
Sets the value of the element at the given offset by reference.
sourcepub fn read(&self) -> Aligned<ReadGuard<'_, T>>
pub fn read(&self) -> Aligned<ReadGuard<'_, T>>
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.
sourcepub fn write(&mut self) -> Aligned<WriteGuard<'_, T>>
pub fn write(&mut self) -> Aligned<WriteGuard<'_, T>>
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.
sourceimpl<T> PoolArray<T>where
T: PoolElement + Copy,
impl<T> PoolArray<T>where
T: PoolElement + Copy,
sourcepub fn from_slice(src: &[T]) -> PoolArray<T>
pub fn from_slice(src: &[T]) -> PoolArray<T>
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
.
sourcepub fn append_slice(&mut self, src: &[T])
pub fn append_slice(&mut self, src: &[T])
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
sourceimpl<T> Clone for PoolArray<T>where
T: PoolElement,
impl<T> Clone for PoolArray<T>where
T: PoolElement,
sourceimpl CoerceFromVariant for PoolArray<Color>
impl CoerceFromVariant for PoolArray<Color>
fn coerce_from_variant(v: &Variant) -> PoolArray<Color>
sourceimpl CoerceFromVariant for PoolArray<GodotString>
impl CoerceFromVariant for PoolArray<GodotString>
fn coerce_from_variant(v: &Variant) -> PoolArray<GodotString>
sourceimpl CoerceFromVariant for PoolArray<Vector2>
impl CoerceFromVariant for PoolArray<Vector2>
fn coerce_from_variant(v: &Variant) -> PoolArray<Vector2>
sourceimpl CoerceFromVariant for PoolArray<Vector3>
impl CoerceFromVariant for PoolArray<Vector3>
fn coerce_from_variant(v: &Variant) -> PoolArray<Vector3>
sourceimpl CoerceFromVariant for PoolArray<f32>
impl CoerceFromVariant for PoolArray<f32>
fn coerce_from_variant(v: &Variant) -> PoolArray<f32>
sourceimpl CoerceFromVariant for PoolArray<i32>
impl CoerceFromVariant for PoolArray<i32>
fn coerce_from_variant(v: &Variant) -> PoolArray<i32>
sourceimpl CoerceFromVariant for PoolArray<u8>
impl CoerceFromVariant for PoolArray<u8>
fn coerce_from_variant(v: &Variant) -> PoolArray<u8>
sourceimpl<T> Debug for PoolArray<T>where
T: PoolElement + Debug,
impl<T> Debug for PoolArray<T>where
T: PoolElement + Debug,
sourceimpl<T> Default for PoolArray<T>where
T: PoolElement,
impl<T> Default for PoolArray<T>where
T: PoolElement,
sourceimpl<'de, T> Deserialize<'de> for PoolArray<T>where
T: Deserialize<'de> + PoolElement,
impl<'de, T> Deserialize<'de> for PoolArray<T>where
T: Deserialize<'de> + PoolElement,
sourcefn deserialize<D>(
deserializer: D
) -> Result<PoolArray<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<PoolArray<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
sourceimpl<T> Drop for PoolArray<T>where
T: PoolElement,
impl<T> Drop for PoolArray<T>where
T: PoolElement,
sourceimpl Export for PoolArray<Color>
impl Export for PoolArray<Color>
sourcefn export_info(_hint: Option<<PoolArray<Color> as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<PoolArray<Color> as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl Export for PoolArray<GodotString>
impl Export for PoolArray<GodotString>
sourcefn export_info(
_hint: Option<<PoolArray<GodotString> as Export>::Hint>
) -> ExportInfo
fn export_info(
_hint: Option<<PoolArray<GodotString> as Export>::Hint>
) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl Export for PoolArray<Vector2>
impl Export for PoolArray<Vector2>
sourcefn export_info(
_hint: Option<<PoolArray<Vector2> as Export>::Hint>
) -> ExportInfo
fn export_info(
_hint: Option<<PoolArray<Vector2> as Export>::Hint>
) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl Export for PoolArray<Vector3>
impl Export for PoolArray<Vector3>
sourcefn export_info(
_hint: Option<<PoolArray<Vector3> as Export>::Hint>
) -> ExportInfo
fn export_info(
_hint: Option<<PoolArray<Vector3> as Export>::Hint>
) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl Export for PoolArray<f32>
impl Export for PoolArray<f32>
sourcefn export_info(_hint: Option<<PoolArray<f32> as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<PoolArray<f32> as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl Export for PoolArray<i32>
impl Export for PoolArray<i32>
sourcefn export_info(_hint: Option<<PoolArray<i32> as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<PoolArray<i32> as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl Export for PoolArray<u8>
impl Export for PoolArray<u8>
sourcefn export_info(_hint: Option<<PoolArray<u8> as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<PoolArray<u8> as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.sourceimpl<T> Extend<T> for PoolArray<T>where
T: PoolElement,
impl<T> Extend<T> for PoolArray<T>where
T: PoolElement,
sourcefn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<T> FromIterator<T> for PoolArray<T>where
T: PoolElement,
impl<T> FromIterator<T> for PoolArray<T>where
T: PoolElement,
sourcefn from_iter<I>(iter: I) -> PoolArray<T>where
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> PoolArray<T>where
I: IntoIterator<Item = T>,
sourceimpl<T> FromVariant for PoolArray<T>where
T: PoolElement,
impl<T> FromVariant for PoolArray<T>where
T: PoolElement,
fn from_variant(variant: &Variant) -> Result<PoolArray<T>, FromVariantError>
sourceimpl<T> NewRef for PoolArray<T>where
T: PoolElement,
impl<T> NewRef for PoolArray<T>where
T: PoolElement,
sourceimpl<T> PartialEq<PoolArray<T>> for PoolArray<T>where
T: PoolElement + PartialEq<T>,
impl<T> PartialEq<PoolArray<T>> for PoolArray<T>where
T: PoolElement + PartialEq<T>,
sourceimpl<T> Serialize for PoolArray<T>where
T: Serialize + PoolElement,
impl<T> Serialize for PoolArray<T>where
T: Serialize + PoolElement,
sourcefn serialize<S>(
&self,
ser: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
ser: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
sourceimpl<T> ToVariant for PoolArray<T>where
T: PoolElement,
impl<T> ToVariant for PoolArray<T>where
T: PoolElement,
fn to_variant(&self) -> Variant
impl<T> Eq for PoolArray<T>where
T: PoolElement + Eq,
impl<T> ToVariantEq for PoolArray<T>where
T: PoolElement + Eq,
Auto Trait Implementations
impl<T> RefUnwindSafe for PoolArray<T>where
<T as PoolElement>::SysArray: RefUnwindSafe,
impl<T> Send for PoolArray<T>where
<T as PoolElement>::SysArray: Send,
impl<T> Sync for PoolArray<T>where
<T as PoolElement>::SysArray: Sync,
impl<T> Unpin for PoolArray<T>where
<T as PoolElement>::SysArray: Unpin,
impl<T> UnwindSafe for PoolArray<T>where
<T as PoolElement>::SysArray: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.