[−][src]Trait arraylib::ArrayShorthand
Shorthand methods those just refer to self.as_slice().smt()
Provided methods
fn index<Idx>(&self, idx: Idx) -> &Idx::Output where
Idx: SliceIndex<[Self::Item]>,
Idx: SliceIndex<[Self::Item]>,
Returns a reference to the value corresponding to the supplied index.
Example
use arraylib::{Array, ArrayShorthand}; fn slice<A>(arr: &A) -> (&A::Item, &[A::Item]) where A: Array, { (arr.index(0), arr.index(1..)) } assert_eq!(slice(&[1, 2, 3]), (&1, &[2, 3][..]))
See also: index_mut
fn index_mut<Idx>(&mut self, idx: Idx) -> &mut Idx::Output where
Idx: SliceIndex<[Self::Item]>,
Idx: SliceIndex<[Self::Item]>,
Returns a unique reference to the value corresponding to the supplied index.
Example
use arraylib::{Array, ArrayShorthand}; fn slice<A>(arr: &mut A) -> &mut [A::Item] where A: Array, { arr.index_mut(1..) } assert_eq!(slice(&mut [1, 2, 3]), &mut [2, 3])
See also: index
fn replace(&mut self, idx: usize, item: Self::Item) -> Self::Item
Replace element of the array
Example
use arraylib::ArrayShorthand; let mut arr = ["hello", "", "world"]; assert_eq!(arr.replace(1, ", "), ""); assert_eq!(arr, ["hello", ", ", "world"])
fn take(&mut self, idx: usize) -> Self::Item where
Self::Item: Default,
Self::Item: Default,
Take element of the array, replacing it with default
Example
use arraylib::ArrayShorthand; let mut arr = [String::from("hello, "), String::from("world")]; assert_eq!(arr.take(1), "world"); assert_eq!(arr, ["hello, ", ""])
fn iter(&self) -> Iter<Self::Item>
Returns an iterator over refs to the array.
Examples
use arraylib::ArrayShorthand; let arr = [1, 2, 4]; let mut iterator = arr.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None);
fn iter_mut(&mut self) -> IterMut<Self::Item>
Returns an iterator that allows modifying each value.
Examples
use arraylib::ArrayShorthand; let mut arr = [1, 2, 4]; for elem in arr.iter_mut() { *elem += 2; } assert_eq!(arr, [3, 4, 6]);