Struct godot::builtin::PackedStringArray
pub struct PackedStringArray { /* private fields */ }
Expand description
Implements Godot’s PackedStringArray
type,
which is a space-efficient array of GString
s.
Check out the book for a tutorial on packed arrays.
Note that, unlike Array
, this type has value semantics: each copy will be independent
of the original. Under the hood, Godot uses copy-on-write, so copies are still cheap
to make.
§Registering properties
You can use both #[var]
and #[export]
with packed arrays. However, since they use copy-on-write, GDScript (for #[var]
) and the
editor (for #[export]
) will effectively keep an independent copy of the array. Writes to the packed array from Rust are thus not
reflected on the other side – you may need to replace the entire array.
See also godot/#76150 for details.
§Thread safety
Usage is safe if the PackedStringArray
is used on a single thread only. Concurrent reads on different threads are also safe,
but any writes must be externally synchronized. The Rust compiler will enforce this as
long as you use only Rust threads, but it cannot protect against concurrent modification
on other threads (e.g. created through GDScript).
Implementations§
§impl PackedStringArray
impl PackedStringArray
pub fn new() -> PackedStringArray
pub fn new() -> PackedStringArray
Constructs an empty array.
pub fn get(&self, index: usize) -> Option<GString>
pub fn get(&self, index: usize) -> Option<GString>
Returns a copy of the value at the specified index, or None
if out-of-bounds.
If you know the index is valid, use the []
operator (Index
/IndexMut
traits) instead.
pub fn contains(&self, value: &GString) -> bool
pub fn contains(&self, value: &GString) -> bool
Returns true
if the array contains the given value.
Godot equivalent: has
pub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the array. Equivalent of size()
in Godot.
pub fn clear(&mut self)
pub fn clear(&mut self)
Clears the array, removing all elements.
pub fn push(&mut self, value: GString)
pub fn push(&mut self, value: GString)
Appends an element to the end of the array. Equivalent of append
and push_back
in GDScript.
pub fn insert(&mut self, index: usize, value: GString)
pub fn insert(&mut self, index: usize, value: GString)
Inserts a new element at a given index in the array. The index must be valid, or at
the end of the array (index == len()
).
Note: On large arrays, this method is much slower than push
as it will move all
the array’s elements after the inserted element. The larger the array, the slower
insert
will be.
pub fn remove(&mut self, index: usize) -> GString
pub fn remove(&mut self, index: usize) -> GString
Removes and returns the element at the specified index. Similar to remove_at
in
GDScript, but also returns the removed value.
On large arrays, this method is much slower than pop_back
as it will move all the array’s
elements after the removed element. The larger the array, the slower remove
will be.
§Panics
If index
is out of bounds.
pub fn fill(&mut self, value: GString)
pub fn fill(&mut self, value: GString)
Assigns the given value to all elements in the array. This can be used together
with resize
to create an array with a given size and initialized elements.
pub fn resize(&mut self, size: usize)
pub fn resize(&mut self, size: usize)
Resizes the array to contain a different number of elements. If the new size is
smaller, elements are removed from the end. If the new size is larger, new elements
are set to Default::default()
.
pub fn extend_array(&mut self, other: &PackedStringArray)
pub fn extend_array(&mut self, other: &PackedStringArray)
Appends another array at the end of this array. Equivalent of append_array
in GDScript.
pub fn to_vec(&self) -> Vec<GString>
pub fn to_vec(&self) -> Vec<GString>
Converts this array to a Rust vector, making a copy of its contents.
pub fn subarray(&self, begin: usize, end: usize) -> PackedStringArray
pub fn subarray(&self, begin: usize, end: usize) -> PackedStringArray
Returns a sub-range begin..end
, as a new packed array.
This method is called slice()
in Godot.
The values of begin
(inclusive) and end
(exclusive) will be clamped to the array size.
To obtain Rust slices, see as_slice
and as_mut_slice
.
pub fn as_slice(&self) -> &[GString]
pub fn as_slice(&self) -> &[GString]
Returns a shared Rust slice of the array.
The resulting slice can be further subdivided or converted into raw pointers.
See also as_mut_slice
to get exclusive slices, and
subarray
to get a sub-array as a copy.
pub fn as_mut_slice(&mut self) -> &mut [GString]
pub fn as_mut_slice(&mut self) -> &mut [GString]
pub fn find(&self, value: &GString, from: Option<usize>) -> Option<usize>
pub fn find(&self, value: &GString, from: Option<usize>) -> Option<usize>
Searches the array for the first occurrence of a value and returns its index, or
None
if not found. Starts searching at index from
; pass None
to search the
entire array.
pub fn rfind(&self, value: &GString, from: Option<usize>) -> Option<usize>
pub fn rfind(&self, value: &GString, from: Option<usize>) -> Option<usize>
Searches the array backwards for the last occurrence of a value and returns its
index, or None
if not found. Starts searching at index from
; pass None
to
search the entire array.
pub fn bsearch(&self, value: &GString) -> usize
pub fn bsearch(&self, value: &GString) -> usize
Finds the index of an existing value in a sorted array using binary search.
If the value is not present in the array, returns the insertion index that would maintain sorting order.
Calling bsearch()
on an unsorted array results in unspecified (but safe) behavior.
pub fn reverse(&mut self)
pub fn reverse(&mut self)
Reverses the order of the elements in the array.
pub fn sort(&mut self)
pub fn sort(&mut self)
Sorts the elements of the array in ascending order.
This sort is stable, since elements inside packed arrays are indistinguishable. Relative order between equal elements thus isn’t observable.
pub fn to_byte_array(&self) -> PackedByteArray
pub fn to_byte_array(&self) -> PackedByteArray
Returns a PackedByteArray
with each value encoded as bytes.
Trait Implementations§
§impl Clone for PackedStringArray
impl Clone for PackedStringArray
§fn clone(&self) -> PackedStringArray
fn clone(&self) -> PackedStringArray
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for PackedStringArray
impl Debug for PackedStringArray
§impl Default for PackedStringArray
impl Default for PackedStringArray
§fn default() -> PackedStringArray
fn default() -> PackedStringArray
§impl Display for PackedStringArray
impl Display for PackedStringArray
§impl Export for PackedStringArray
impl Export for PackedStringArray
§fn default_export_info() -> PropertyHintInfo
fn default_export_info() -> PropertyHintInfo
§impl Extend<GString> for PackedStringArray
impl Extend<GString> for PackedStringArray
Extends aPackedStringArray
with the contents of an iterator
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = GString>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = GString>,
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
)§impl From<&[GString]> for PackedStringArray
impl From<&[GString]> for PackedStringArray
Creates a PackedStringArray
from the given slice.
§fn from(slice: &[GString]) -> PackedStringArray
fn from(slice: &[GString]) -> PackedStringArray
§impl<const N: usize> From<&[GString; N]> for PackedStringArray
impl<const N: usize> From<&[GString; N]> for PackedStringArray
Creates a PackedStringArray
from the given Rust array.
§fn from(arr: &[GString; N]) -> PackedStringArray
fn from(arr: &[GString; N]) -> PackedStringArray
§impl From<&Array<Variant>> for PackedStringArray
impl From<&Array<Variant>> for PackedStringArray
§fn from(other: &Array<Variant>) -> PackedStringArray
fn from(other: &Array<Variant>) -> PackedStringArray
§impl From<&PackedStringArray> for Array<Variant>
impl From<&PackedStringArray> for Array<Variant>
§fn from(other: &PackedStringArray) -> Array<Variant>
fn from(other: &PackedStringArray) -> Array<Variant>
§impl From<Vec<GString>> for PackedStringArray
impl From<Vec<GString>> for PackedStringArray
Creates a PackedStringArray
from the given Rust vec.
§fn from(vec: Vec<GString>) -> PackedStringArray
fn from(vec: Vec<GString>) -> PackedStringArray
§impl FromGodot for PackedStringArray
impl FromGodot for PackedStringArray
§fn try_from_godot(
via: <PackedStringArray as GodotConvert>::Via,
) -> Result<PackedStringArray, ConvertError>
fn try_from_godot( via: <PackedStringArray as GodotConvert>::Via, ) -> Result<PackedStringArray, ConvertError>
Err
on failure.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl FromIterator<GString> for PackedStringArray
impl FromIterator<GString> for PackedStringArray
Creates a PackedStringArray
from an iterator.
§fn from_iter<I>(iter: I) -> PackedStringArraywhere
I: IntoIterator<Item = GString>,
fn from_iter<I>(iter: I) -> PackedStringArraywhere
I: IntoIterator<Item = GString>,
§impl GodotConvert for PackedStringArray
impl GodotConvert for PackedStringArray
§type Via = PackedStringArray
type Via = PackedStringArray
Self
is represented in Godot.§impl Index<usize> for PackedStringArray
impl Index<usize> for PackedStringArray
§impl IndexMut<usize> for PackedStringArray
impl IndexMut<usize> for PackedStringArray
§impl PartialEq for PackedStringArray
impl PartialEq for PackedStringArray
§fn eq(&self, other: &PackedStringArray) -> bool
fn eq(&self, other: &PackedStringArray) -> bool
self
and other
values to be equal, and is used
by ==
.§impl ToGodot for PackedStringArray
impl ToGodot for PackedStringArray
§fn to_godot(&self) -> <PackedStringArray as GodotConvert>::Via
fn to_godot(&self) -> <PackedStringArray as GodotConvert>::Via
§fn into_godot(self) -> <PackedStringArray as GodotConvert>::Via
fn into_godot(self) -> <PackedStringArray as GodotConvert>::Via
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
§impl TypeStringHint for PackedStringArray
impl TypeStringHint for PackedStringArray
§fn type_string() -> String
fn type_string() -> String
§impl Var for PackedStringArray
impl Var for PackedStringArray
fn get_property(&self) -> <PackedStringArray as GodotConvert>::Via
fn set_property(&mut self, value: <PackedStringArray as GodotConvert>::Via)
fn property_hint() -> PropertyHintInfo
impl ArrayElement for PackedStringArray
impl Eq for PackedStringArray
impl GodotType for PackedStringArray
Auto Trait Implementations§
impl Freeze for PackedStringArray
impl RefUnwindSafe for PackedStringArray
impl !Send for PackedStringArray
impl !Sync for PackedStringArray
impl Unpin for PackedStringArray
impl UnwindSafe for PackedStringArray
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)