Struct Array1

Source
pub struct Array1<T: ZeroInit> { /* private fields */ }
Expand description

§1-D array accessor class.

This class represents 1-D array accessor. Array accessor provides array-like data read/write functions, but does not handle memory management. Thus, it is more like a random access iterator, but with multi-dimension support.

  • tparam T - Array value type.

Implementations§

Source§

impl<T: ZeroInit> Array1<T>

Source

pub fn new_default() -> Array1<T>

Constructs zero-sized 1-D array.

use vox_geometry_rust::array1::Array1;
let arr: Array1<f32> = Array1::new_default();
assert_eq!(0, arr.size());
Source

pub fn new(size: usize, init_val: Option<T>) -> Array1<T>

Constructs 1-D array with given \p size and fill it with \p initVal.

  • parameter: size Initial size of the array.
  • parameter: initVal Initial value of each array element.
use vox_geometry_rust::array1::Array1;
let arr = Array1::new(9, Some(1.5));
assert_eq!(9, arr.size());
for i in 0..9 {
    assert_eq!(1.5, arr[i]);
}
Source

pub fn new_lst(lst: Vec<T>) -> Array1<T>

\brief Constructs 1-D array with given initializer list \p lst.

This constructor will build 1-D array with given initializer list \p lst such as

use vox_geometry_rust::array1::Array1;
let arr: Array1<f32> = Array1::new_lst(vec![1.0, 2.0, 4.0, 9.0, 3.0]);
  • parameter: lst Initializer list that should be copy to the new array.
use vox_geometry_rust::array1::Array1;
let arr = Array1::new_lst(vec![1.0,  2.0,  3.0,  4.0]);
assert_eq!(4, arr.size());
for i in 0..4 {
    assert_eq!(i as f32 + 1.0, arr[i]);
}
Source§

impl<T: ZeroInit> Array1<T>

Source

pub fn set_scalar(&mut self, value: T)

Sets entire array with given \p value.

use vox_geometry_rust::array1::Array1;
let mut arr1 = Array1::new(12, Some(-1.0));
arr1.set_scalar(3.5);
for a in arr1.iter() {
    assert_eq!(3.5, *a);
}
Source

pub fn set_self(&mut self, other: Array1<T>)

Copies given array \p other to this array.

use vox_geometry_rust::array1::Array1;
let mut arr1 = Array1::new(12, Some(-1.0));
arr1.set_self(Array1::new_default());
assert_eq!(0, arr1.size());
Source

pub fn set_lst(&mut self, lst: Vec<T>)

Copies given initializer list \p lst to this array.

use vox_geometry_rust::array1::Array1;
let mut arr2 = Array1::new(12, Some(-1.0));
arr2.set_lst(vec![2.0, 5.0, 9.0, -1.0]);
assert_eq!(4, arr2.size());
assert_eq!(2.0, arr2[0]);
assert_eq!(5.0, arr2[1]);
assert_eq!(9.0, arr2[2]);
assert_eq!(-1.0, arr2[3]);
Source

pub fn clear(&mut self)

Clears the array and resizes to zero.

use vox_geometry_rust::array1::Array1;
let mut arr1 = Array1::new_lst(vec![2.0, 5.0, 9.0, -1.0]);
arr1.clear();
assert_eq!(0, arr1.size());
Source

pub fn resize(&mut self, size: usize, init_val: Option<T>)

Resizes the array with \p size and fill the new element with \p initVal.

use vox_geometry_rust::array1::Array1;
let mut arr:Array1<f32>  = Array1::new_default();
arr.resize(9, None);
assert_eq!(9, arr.size());
for i in 0..9 {
    assert_eq!(0.0, arr[i]);
}

arr.resize(12, Some(4.0));
assert_eq!(12, arr.size());
for i in 0..12 {
    if i < 9 {
        assert_eq!(0.0, arr[i]);
    } else {
        assert_eq!(4.0, arr[i]);
    }
}
Source

pub fn at_mut(&mut self, i: usize) -> &mut T

Returns the reference to the i-th element.

Source

pub fn at(&self, i: usize) -> &T

Returns the const reference to the i-th element.

Source

pub fn size(&self) -> usize

Returns size of the array.

Source

pub fn swap(&mut self, other: &mut Array1<T>)

Swaps the content of the array with \p other array.

Source

pub fn push(&mut self, new_val: T)

Appends single value \p newVal at the end of the array.

Source

pub fn append(&mut self, other: &mut Array1<T>)

Appends \p other array at the end of the array.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns the iterator of the array.

use vox_geometry_rust::array1::Array1;
let mut arr1:Array1<f32> = Array1::new_lst(vec![6.0, 4.0, 1.0, -5.0]);
let mut i:usize = 0;
for elem in arr1.iter_mut() {
    assert_eq!(&mut arr1[i], elem);
    i += 1;
}
Source

pub fn iter(&self) -> Iter<'_, T>

Returns the const iterator of the array.

use vox_geometry_rust::array1::Array1;
let arr1:Array1<f32> = Array1::new_lst(vec![6.0, 4.0, 1.0, -5.0]);
let mut i:usize = 0;
for elem in arr1.iter() {
    assert_eq!(& arr1[i], elem);
    i += 1;
}

Trait Implementations§

Source§

impl<T: ZeroInit> Index<usize> for Array1<T>

Returns the const reference to i-th element.

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: ZeroInit> IndexMut<usize> for Array1<T>

Returns the reference to i-th element.

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Array1<T>

§

impl<T> RefUnwindSafe for Array1<T>
where T: RefUnwindSafe,

§

impl<T> Send for Array1<T>
where T: Send,

§

impl<T> Sync for Array1<T>
where T: Sync,

§

impl<T> Unpin for Array1<T>
where T: Unpin,

§

impl<T> UnwindSafe for Array1<T>
where T: UnwindSafe,

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V