Array

Struct Array 

Source
pub struct Array { /* private fields */ }
Expand description

An array data structure that supports various operations.

Implementations§

Source§

impl Array

Source

pub fn get_count(&self) -> i64

Gets the number of items in the array.

Source

pub fn is_empty(&self) -> bool

Gets whether the array is empty or not.

Source

pub fn add_range(&mut self, other: &Array)

Adds all items from another array to the end of this array.

§Arguments
  • other - Another array object.
Source

pub fn remove_from(&mut self, other: &Array)

Removes all items from this array that are also in another array.

§Arguments
  • other - Another array object.
Source

pub fn clear(&mut self)

Removes all items from the array.

Source

pub fn reverse(&mut self)

Reverses the order of the items in the array.

Source

pub fn shrink(&mut self)

Removes any empty slots from the end of the array. This method is used to release the unused memory this array holds.

Source

pub fn swap(&mut self, index_a: i32, index_b: i32)

Swaps the items at two given indices.

§Arguments
  • index_a - The first index.
  • index_b - The second index.
Source

pub fn remove_at(&mut self, index: i32) -> bool

Removes the item at the given index.

§Arguments
  • index - The index to remove.
§Returns
  • bool - true if an item was removed, false otherwise.
Source

pub fn fast_remove_at(&mut self, index: i32) -> bool

Removes the item at the given index without preserving the order of the array.

§Arguments
  • index - The index to remove.
§Returns
  • bool - true if an item was removed, false otherwise.
Source

pub fn new() -> Array

Creates a new array object

Source§

impl Array

Source

pub fn set<'a, T>(&mut self, index: i32, v: T)
where T: IntoValue<'a>,

Sets the item at the given index.

§Arguments
  • index - The index to set, should be 0 based.
  • item - The new item value.
Source

pub fn get(&self, index: i32) -> Option<Value>

Gets the item at the given index.

§Arguments
  • index - The index to get, should be 0 based.
§Returns
  • Option<Value> - The item value.
Source

pub fn first(&self) -> Option<Value>

The first item in the array.

Source

pub fn last(&self) -> Option<Value>

The last item in the array.

Source

pub fn random_object(&self) -> Option<Value>

A random item from the array.

Source

pub fn add<'a, T>(&mut self, v: T) -> &mut Self
where T: IntoValue<'a>,

Adds an item to the end of the array.

§Arguments
  • item - The item to add.
Source

pub fn insert<'a, T>(&mut self, index: i32, v: T)
where T: IntoValue<'a>,

Inserts an item at the given index, shifting other items to the right.

§Arguments
  • index - The index to insert at.
  • item - The item to insert.
Source

pub fn contains<'a, T>(&self, v: T) -> bool
where T: IntoValue<'a>,

Checks whether the array contains a given item.

§Arguments
  • item - The item to check.
§Returns
  • bool - True if the item is found, false otherwise.
Source

pub fn index<'a, T>(&self, v: T) -> i32
where T: IntoValue<'a>,

Gets the index of a given item.

§Arguments
  • item - The item to search for.
§Returns
  • i32 - The index of the item, or -1 if it is not found.
Source

pub fn remove_last(&mut self) -> Option<Value>

Removes and returns the last item in the array.

§Returns
  • Option<Value> - The last item removed from the array.
Source

pub fn fast_remove<'a, T>(&mut self, v: T) -> bool
where T: IntoValue<'a>,

Removes the first occurrence of a given item from the array without preserving order.

§Arguments
  • item - The item to remove.
§Returns
  • bool - True if the item was found and removed, false otherwise.

Trait Implementations§

Source§

impl Clone for Array

Source§

fn clone(&self) -> Array

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for Array

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IObject for Array

Source§

fn raw(&self) -> i64

Source§

fn obj(&self) -> &dyn IObject

Source§

fn as_any(&self) -> &dyn Any

Source§

fn get_id(&self) -> i32

Auto Trait Implementations§

§

impl Freeze for Array

§

impl RefUnwindSafe for Array

§

impl Send for Array

§

impl Sync for Array

§

impl Unpin for Array

§

impl UnwindSafe for Array

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.