Struct purp_value::types::array::Array

source ·
pub struct Array {
    pub values: Vec<Value>,
}
Expand description

Represents an array of Values.

Fields§

§values: Vec<Value>

Implementations§

source§

impl Array

source

pub fn new() -> Self

Creates a new empty Array.

Examples
use my_crate::Array;

let empty_array = Array::new();
assert_eq!(empty_array.len(), 0);
source

pub fn push(&mut self, value: Value)

Appends a value to the end of the array.

Examples
use my_crate::{Array, Value};

let mut array = Array::new();
array.push(Value::from(42));
array.push(Value::from("hello"));

assert_eq!(array.len(), 2);
assert_eq!(array.get(0), Some(&Value::from(42)));
assert_eq!(array.get(1), Some(&Value::from("hello")));
source

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

Removes the last element from the array and returns it, or None if the array is empty.

Examples
use my_crate::{Array, Value};

let mut array = Array::new();
array.push(Value::from(42));

let popped_value = array.pop();
assert_eq!(popped_value, Some(Value::from(42)));

let empty_array = Array::new();
let empty_popped_value = empty_array.pop();
assert_eq!(empty_popped_value, None);
source

pub fn len(&self) -> usize

Returns the number of elements in the array.

Examples
use my_crate::{Array, Value};

let mut array = Array::new();
assert_eq!(array.len(), 0);

array.push(Value::from(42));
assert_eq!(array.len(), 1);
source

pub fn is_empty(&self) -> bool

Returns true if the array contains no elements.

Examples
use my_crate::{Array, Value};

let empty_array = Array::new();
assert!(empty_array.is_empty());

let mut array = Array::new();
array.push(Value::from(42));
assert!(!array.is_empty());
source

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

Returns a reference to the value at the specified index, or None if the index is out of bounds.

source

pub fn get_mut(&mut self, index: usize) -> Option<&mut Value>

Returns a mutable reference to the value at the specified index, or None if the index is out of bounds.

Trait Implementations§

source§

impl Clone for Array

source§

fn clone(&self) -> Array

Returns a copy 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 Debug for Array

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Array

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Array

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: AsRef<str>, V: Into<Value>> From<BTreeMap<K, V, Global>> for Array

source§

fn from(map: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl<K: AsRef<str>, V: Into<Value>> From<HashMap<K, V, RandomState>> for Array

source§

fn from(map: HashMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl From<Value> for Array

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Value>> From<Vec<T, Global>> for Array

source§

fn from(values: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a> IntoIterator for &'a Array

§

type Item = &'a Value

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Value>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Array

§

type Item = &'a mut Value

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, Value>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Array

§

type Item = Value

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<Array as IntoIterator>::Item, Global>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<Array> for Array

source§

fn eq(&self, other: &Array) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TypeToValue for Array

source§

fn to_value(&self) -> Value

Converts the data type to a Value enum.
source§

impl StructuralPartialEq for Array

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.