pub trait ArrayShorthand: Array {
// Provided methods
fn index<Idx>(&self, idx: Idx) -> &Idx::Output
where Idx: SliceIndex<[Self::Item]> { ... }
fn index_mut<Idx>(&mut self, idx: Idx) -> &mut Idx::Output
where Idx: SliceIndex<[Self::Item]> { ... }
fn replace(&mut self, idx: usize, item: Self::Item) -> Self::Item { ... }
fn take(&mut self, idx: usize) -> Self::Item
where Self::Item: Default { ... }
fn iter(&self) -> Iter<'_, Self::Item> { ... }
fn iter_mut(&mut self) -> IterMut<'_, Self::Item> { ... }
}Expand description
Shorthand methods those just refer to self.as_slice().smt()
Provided Methods§
Sourcefn index<Idx>(&self, idx: Idx) -> &Idx::Outputwhere
Idx: SliceIndex<[Self::Item]>,
fn index<Idx>(&self, idx: Idx) -> &Idx::Outputwhere
Idx: SliceIndex<[Self::Item]>,
Sourcefn index_mut<Idx>(&mut self, idx: Idx) -> &mut Idx::Outputwhere
Idx: SliceIndex<[Self::Item]>,
fn index_mut<Idx>(&mut self, idx: Idx) -> &mut Idx::Outputwhere
Idx: SliceIndex<[Self::Item]>,
Sourcefn replace(&mut self, idx: usize, item: Self::Item) -> Self::Item
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"])Sourcefn take(&mut self, idx: usize) -> Self::Item
fn take(&mut self, idx: usize) -> Self::Item
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, ", ""])Sourcefn iter(&self) -> Iter<'_, Self::Item>
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);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.