pub struct ArrayWrapper<A> { /* private fields */ }Expand description
Wrapper over array types. It implements the same1 traits as
array, but not for only arrays of sizes 0..=32 but for all arrays,
those sizes are supported by the crate2:
DebugIntoIteratorPartialEq,PartialOrd,Eq,OrdHashAsRef,AsMut(both forAand[A::Item])Borrow,BorrowMutIndex,IndexMutDefaultTryFrom
Note: Implementations of the most trai just copy-pasted from std
§Examples
use arraylib::{ArrayExt, ArrayWrapper};
let arr = [1, 2, 3].wrap();
assert_eq!(arr, [1, 2, 3]);
assert_eq!(format!("{:?}", arr), "[1, 2, 3]");
assert!(arr < [1, 4, 0]);
assert_eq!(arr[1], 2);
assert!(arr.into_iter().eq(vec![1, 2, 3].into_iter()));
assert_eq!(<ArrayWrapper<[i32; 3]> as Default>::default(), [0, 0, 0]);use arraylib::{ArrayExt, ArrayWrapper};
use std::borrow::{Borrow, BorrowMut};
let mut arr = [1, 2, 3].wrap();
let slice: &[i32] = arr.as_ref();
assert_eq!(slice, &[1, 2, 3]);use arraylib::ArrayExt;
use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
let mut hasher = DefaultHasher::new();
[1, 2, 3].wrap().hash(&mut hasher);
let hash0 = hasher.finish();
let mut hasher = DefaultHasher::new();
[1, 2, 3].hash(&mut hasher);
let hash1 = hasher.finish();
assert_eq!(hash0, hash1);In difference with std, ArrayWrapper is iterable:
use arraylib::ArrayExt;
let arr = [0, 3, 45, 91].wrap();
for x in arr {}- IntoIterator (on std’s
arrayIntoIteratoris implemented only on&[T; N]and on&mut [T; N]while on ArrayWrapper it’s implemented directly (usingIterMove)) - In some traits instead of
TryFromSliceErrorthere isSizeError Copy/Cloneare implemented only whenA: Copy/Cloneand not whenA::Item: Copy/Clonebecause we can’t use compiler magic :(
differences: ↩
See Sizes Limitations paragraph in crate docs. ↩
Implementations§
Source§impl<A> ArrayWrapper<A>where
A: Array,
impl<A> ArrayWrapper<A>where
A: Array,
Sourcepub fn new(inner: A) -> Self
pub fn new(inner: A) -> Self
Create new ArrayWrapper
use arraylib::ArrayWrapper;
let arr = ArrayWrapper::new([0, 1, 2, 3]);
println!("{:?}", arr);Sourcepub fn into_inner(self) -> A
pub fn into_inner(self) -> A
Destruct ArrayWrapper into inner array
use arraylib::ArrayWrapper;
let arr = ArrayWrapper::new([0, 1, 2, 3]);
// ...
let arr = arr.into_inner();
println!("{:?}", arr);Trait Implementations§
Source§impl<A> Array for ArrayWrapper<A>where
A: Array,
§Safety
ArrayWrapper has #[repr(transparent)] so it has the same ABI as A.
So if A is array then so is ArrayWrapper.
impl<A> Array for ArrayWrapper<A>where
A: Array,
§Safety
ArrayWrapper has #[repr(transparent)] so it has the same ABI as A.
So if A is array then so is ArrayWrapper.
Source§type Maybe = ArrayWrapper<<A as Array>::Maybe>
type Maybe = ArrayWrapper<<A as Array>::Maybe>
Same array but item is wrapped with
MaybeUninit<_>. Read moreSource§fn into_boxed_slice(self) -> Box<[Self::Item]>
fn into_boxed_slice(self) -> Box<[Self::Item]>
Available on crate feature
alloc only.Converts
self into Box<[Self::Item]>Source§fn as_mut_slice(&mut self) -> &mut [Self::Item]
fn as_mut_slice(&mut self) -> &mut [Self::Item]
Extracts a mutable slice of the entire array. Read more
Source§fn try_unfold<St, F, E>(init: St, f: F) -> Result<Self, E>
fn try_unfold<St, F, E>(init: St, f: F) -> Result<Self, E>
Create new array, filled with elements returned by
f. If f return
Err then this method also return Err. Read moreSource§fn unfold<St, F>(init: St, f: F) -> Self
fn unfold<St, F>(init: St, f: F) -> Self
Create new array, filled with elements returned by
f Read moreSource§fn try_from_fn<F, E>(f: F) -> Result<Self, E>
fn try_from_fn<F, E>(f: F) -> Result<Self, E>
Create new array, filled with elements returned by
f. If f return
Err then this method also return Err. Read moreSource§fn try_from_iter<I>(iter: I) -> Option<Self>where
I: IntoIterator<Item = Self::Item>,
fn try_from_iter<I>(iter: I) -> Option<Self>where
I: IntoIterator<Item = Self::Item>,
Creates an array from an iterator. Read more
Source§fn into_uninit(self) -> Self::Maybe
fn into_uninit(self) -> Self::Maybe
Converts self into
[MaybeUninit<Self::Item>; Self::Size]. This
function is used internally in this crate for some unsafe code. Read moreSource§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self::Item>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self::Item>,
Creates an array from an iterator. Read more
Source§unsafe fn assume_init(uninit: Self::Maybe) -> Self
unsafe fn assume_init(uninit: Self::Maybe) -> Self
Extracts the values from the
MaybeUninit<T> containers. Read moreSource§impl<A> AsMut<A> for ArrayWrapper<A>
impl<A> AsMut<A> for ArrayWrapper<A>
Source§impl<A> AsRef<A> for ArrayWrapper<A>
impl<A> AsRef<A> for ArrayWrapper<A>
Source§impl<A> BorrowMut<[<A as Array>::Item]> for ArrayWrapper<A>where
A: Array,
impl<A> BorrowMut<[<A as Array>::Item]> for ArrayWrapper<A>where
A: Array,
Source§fn borrow_mut(&mut self) -> &mut [A::Item]
fn borrow_mut(&mut self) -> &mut [A::Item]
Mutably borrows from an owned value. Read more
Source§impl<A: Clone> Clone for ArrayWrapper<A>
impl<A: Clone> Clone for ArrayWrapper<A>
Source§fn clone(&self) -> ArrayWrapper<A>
fn clone(&self) -> ArrayWrapper<A>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<A> Debug for ArrayWrapper<A>
impl<A> Debug for ArrayWrapper<A>
Source§impl<A> Default for ArrayWrapper<A>
impl<A> Default for ArrayWrapper<A>
Source§impl<A> Hash for ArrayWrapper<A>
impl<A> Hash for ArrayWrapper<A>
Source§impl<A, Idx> Index<Idx> for ArrayWrapper<A>
impl<A, Idx> Index<Idx> for ArrayWrapper<A>
Source§impl<A, Idx> IndexMut<Idx> for ArrayWrapper<A>
impl<A, Idx> IndexMut<Idx> for ArrayWrapper<A>
Source§impl<A> IntoIterator for ArrayWrapper<A>where
A: Array,
impl<A> IntoIterator for ArrayWrapper<A>where
A: Array,
Source§impl<A> Ord for ArrayWrapper<A>
impl<A> Ord for ArrayWrapper<A>
Source§impl<'t, A, T> PartialEq<&'t [T]> for ArrayWrapper<A>
impl<'t, A, T> PartialEq<&'t [T]> for ArrayWrapper<A>
Source§impl<'t, A, T> PartialEq<&'t mut [T]> for ArrayWrapper<A>
impl<'t, A, T> PartialEq<&'t mut [T]> for ArrayWrapper<A>
Source§impl<A, T> PartialEq<[T]> for ArrayWrapper<A>
impl<A, T> PartialEq<[T]> for ArrayWrapper<A>
Source§impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t [T]
impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t [T]
Source§impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t mut [T]
impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t mut [T]
Source§impl<A, T> PartialEq<ArrayWrapper<A>> for [T]
impl<A, T> PartialEq<ArrayWrapper<A>> for [T]
Source§impl<A, B> PartialEq<B> for ArrayWrapper<A>
impl<A, B> PartialEq<B> for ArrayWrapper<A>
Source§impl<A, B> PartialOrd<B> for ArrayWrapper<A>
impl<A, B> PartialOrd<B> for ArrayWrapper<A>
Source§impl<'a, A> TryFrom<&'a [<A as Array>::Item]> for &'a ArrayWrapper<A>where
A: Array,
Alias for ArrayExt::try_ref_cast
impl<'a, A> TryFrom<&'a [<A as Array>::Item]> for &'a ArrayWrapper<A>where
A: Array,
Alias for ArrayExt::try_ref_cast
§Examples
use arraylib::ArrayWrapper;
use core::convert::TryInto;
let slice = &[0, 1, 2][..];
let arr: &ArrayWrapper<[i32; 3]> = slice.try_into().unwrap();
assert_eq!(arr, &ArrayWrapper::new([0, 1, 2]))Source§impl<'a, A> TryFrom<&'a mut [<A as Array>::Item]> for &'a mut ArrayWrapper<A>where
A: Array,
Alias for ArrayExt::try_mut_cast
impl<'a, A> TryFrom<&'a mut [<A as Array>::Item]> for &'a mut ArrayWrapper<A>where
A: Array,
Alias for ArrayExt::try_mut_cast
§Examples
use arraylib::ArrayWrapper;
use core::convert::TryInto;
let slice = &mut [0, 1, 2][..];
let arr: &mut ArrayWrapper<[i32; 3]> = slice.try_into().unwrap();
assert_eq!(arr, &ArrayWrapper::new([0, 1, 2]))impl<A: Copy> Copy for ArrayWrapper<A>
impl<A> Eq for ArrayWrapper<A>
Auto Trait Implementations§
impl<A> Freeze for ArrayWrapper<A>where
A: Freeze,
impl<A> RefUnwindSafe for ArrayWrapper<A>where
A: RefUnwindSafe,
impl<A> Send for ArrayWrapper<A>where
A: Send,
impl<A> Sync for ArrayWrapper<A>where
A: Sync,
impl<A> Unpin for ArrayWrapper<A>where
A: Unpin,
impl<A> UnwindSafe for ArrayWrapper<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<A> ArrayExt for Awhere
A: Array,
impl<A> ArrayExt for Awhere
A: Array,
Source§fn iter_move(self) -> IterMove<Self> ⓘ
fn iter_move(self) -> IterMove<Self> ⓘ
Creates iterator which moves elements out of array. Read more
Source§fn concat_arr<A, R>(self, other: A) -> R
fn concat_arr<A, R>(self, other: A) -> R
Example Read more
Source§fn into_array<A>(self) -> Result<A, Self>
fn into_array<A>(self) -> Result<A, Self>
Converts
self into an array. This function will return Some(_) if
sizes of Self and A are the same and None otherwise. Read moreSource§fn into_vec(self) -> Vec<Self::Item>
fn into_vec(self) -> Vec<Self::Item>
Available on crate feature
alloc only.Converts
self into a vector without clones. Read moreSource§fn wrap(self) -> ArrayWrapper<Self>
fn wrap(self) -> ArrayWrapper<Self>
Wrap
self into ArrayWrapperSource§unsafe fn ref_cast_unchecked(slice: &[Self::Item]) -> &Self
unsafe fn ref_cast_unchecked(slice: &[Self::Item]) -> &Self
Source§unsafe fn mut_cast_unchecked(slice: &mut [Self::Item]) -> &mut Self
unsafe fn mut_cast_unchecked(slice: &mut [Self::Item]) -> &mut Self
Source§impl<A> ArrayShorthand for Awhere
A: Array,
impl<A> ArrayShorthand for Awhere
A: Array,
Source§fn index<Idx>(&self, idx: Idx) -> &Idx::Outputwhere
Idx: SliceIndex<[Self::Item]>,
fn index<Idx>(&self, idx: Idx) -> &Idx::Outputwhere
Idx: SliceIndex<[Self::Item]>,
Returns a reference to the value corresponding to the supplied index. Read more
Source§fn 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]>,
Returns a unique reference to the value corresponding to the supplied
index. Read more
Source§fn 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 Read more
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more