Struct PackedFloat64Array
pub struct PackedFloat64Array { /* private fields */ }
Expand description
Implements Godot’s PackedFloat64Array
type,
which is a space-efficient array of f64
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 PackedFloat64Array
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 PackedFloat64Array
impl PackedFloat64Array
pub fn new() -> PackedFloat64Array
pub fn new() -> PackedFloat64Array
Constructs an empty array.
pub fn get(&self, index: usize) -> Option<f64>
pub fn get(&self, index: usize) -> Option<f64>
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: &f64) -> bool
pub fn contains(&self, value: &f64) -> 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: f64)
pub fn push(&mut self, value: f64)
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: f64)
pub fn insert(&mut self, index: usize, value: f64)
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) -> f64
pub fn remove(&mut self, index: usize) -> f64
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: f64)
pub fn fill(&mut self, value: f64)
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: &PackedFloat64Array)
pub fn extend_array(&mut self, other: &PackedFloat64Array)
Appends another array at the end of this array. Equivalent of append_array
in GDScript.
pub fn to_vec(&self) -> Vec<f64>
pub fn to_vec(&self) -> Vec<f64>
Converts this array to a Rust vector, making a copy of its contents.
pub fn subarray(&self, begin: usize, end: usize) -> PackedFloat64Array
pub fn subarray(&self, begin: usize, end: usize) -> PackedFloat64Array
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) -> &[f64]
pub fn as_slice(&self) -> &[f64]
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 [f64]
pub fn as_mut_slice(&mut self) -> &mut [f64]
pub fn find(&self, value: &f64, from: Option<usize>) -> Option<usize>
pub fn find(&self, value: &f64, 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: &f64, from: Option<usize>) -> Option<usize>
pub fn rfind(&self, value: &f64, 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: &f64) -> usize
pub fn bsearch(&self, value: &f64) -> 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 ArrayElement for PackedFloat64Array
impl ArrayElement for PackedFloat64Array
fn debug_validate_elements(_array: &Array<Self>) -> Result<(), ConvertError>
§impl Clone for PackedFloat64Array
impl Clone for PackedFloat64Array
§fn clone(&self) -> PackedFloat64Array
fn clone(&self) -> PackedFloat64Array
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for PackedFloat64Array
impl Debug for PackedFloat64Array
§impl Default for PackedFloat64Array
impl Default for PackedFloat64Array
§fn default() -> PackedFloat64Array
fn default() -> PackedFloat64Array
§impl Display for PackedFloat64Array
impl Display for PackedFloat64Array
§impl Drop for PackedFloat64Array
impl Drop for PackedFloat64Array
§impl Export for PackedFloat64Array
impl Export for PackedFloat64Array
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§fn as_node_class() -> Option<ClassName>
fn as_node_class() -> Option<ClassName>
§impl Extend<f64> for PackedFloat64Array
impl Extend<f64> for PackedFloat64Array
Extends aPackedFloat64Array
with the contents of an iterator
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = f64>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = f64>,
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<&[f64]> for PackedFloat64Array
impl From<&[f64]> for PackedFloat64Array
Creates a PackedFloat64Array
from the given slice.
§fn from(slice: &[f64]) -> PackedFloat64Array
fn from(slice: &[f64]) -> PackedFloat64Array
§impl<const N: usize> From<&[f64; N]> for PackedFloat64Array
impl<const N: usize> From<&[f64; N]> for PackedFloat64Array
Creates a PackedFloat64Array
from the given Rust array.
§fn from(arr: &[f64; N]) -> PackedFloat64Array
fn from(arr: &[f64; N]) -> PackedFloat64Array
§impl From<&Array<Variant>> for PackedFloat64Array
impl From<&Array<Variant>> for PackedFloat64Array
§fn from(other: &Array<Variant>) -> PackedFloat64Array
fn from(other: &Array<Variant>) -> PackedFloat64Array
§impl From<&PackedFloat64Array> for Array<Variant>
impl From<&PackedFloat64Array> for Array<Variant>
§fn from(other: &PackedFloat64Array) -> Array<Variant>
fn from(other: &PackedFloat64Array) -> Array<Variant>
§impl<const N: usize> From<[f64; N]> for PackedFloat64Array
impl<const N: usize> From<[f64; N]> for PackedFloat64Array
Creates a PackedFloat64Array
from the given Rust array.
§fn from(arr: [f64; N]) -> PackedFloat64Array
fn from(arr: [f64; N]) -> PackedFloat64Array
§impl From<Vec<f64>> for PackedFloat64Array
impl From<Vec<f64>> for PackedFloat64Array
Creates a PackedFloat64Array
from the given Rust vec.
§fn from(vec: Vec<f64>) -> PackedFloat64Array
fn from(vec: Vec<f64>) -> PackedFloat64Array
§impl FromGodot for PackedFloat64Array
impl FromGodot for PackedFloat64Array
§fn try_from_godot(
via: <PackedFloat64Array as GodotConvert>::Via,
) -> Result<PackedFloat64Array, ConvertError>
fn try_from_godot( via: <PackedFloat64Array as GodotConvert>::Via, ) -> Result<PackedFloat64Array, 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<f64> for PackedFloat64Array
impl FromIterator<f64> for PackedFloat64Array
Creates a PackedFloat64Array
from an iterator.
§fn from_iter<I>(iter: I) -> PackedFloat64Arraywhere
I: IntoIterator<Item = f64>,
fn from_iter<I>(iter: I) -> PackedFloat64Arraywhere
I: IntoIterator<Item = f64>,
§impl GodotConvert for PackedFloat64Array
impl GodotConvert for PackedFloat64Array
§type Via = PackedFloat64Array
type Via = PackedFloat64Array
Self
is represented in Godot.§impl Index<usize> for PackedFloat64Array
impl Index<usize> for PackedFloat64Array
§impl IndexMut<usize> for PackedFloat64Array
impl IndexMut<usize> for PackedFloat64Array
§impl PartialEq for PackedFloat64Array
impl PartialEq for PackedFloat64Array
§impl ToGodot for PackedFloat64Array
impl ToGodot for PackedFloat64Array
§type ToVia<'v> = <PackedFloat64Array as GodotConvert>::Via
type ToVia<'v> = <PackedFloat64Array as GodotConvert>::Via
to_godot()
, which differs from Via
for pass-by-reference types.§fn to_godot(&self) -> <PackedFloat64Array as ToGodot>::ToVia<'_>
fn to_godot(&self) -> <PackedFloat64Array as ToGodot>::ToVia<'_>
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
§impl Var for PackedFloat64Array
impl Var for PackedFloat64Array
fn get_property(&self) -> <PackedFloat64Array as GodotConvert>::Via
fn set_property(&mut self, value: <PackedFloat64Array as GodotConvert>::Via)
§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.impl GodotType for PackedFloat64Array
Auto Trait Implementations§
impl Freeze for PackedFloat64Array
impl RefUnwindSafe for PackedFloat64Array
impl !Send for PackedFloat64Array
impl !Sync for PackedFloat64Array
impl Unpin for PackedFloat64Array
impl UnwindSafe for PackedFloat64Array
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)