[−][src]Struct arraylib::ArrayWrapper
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:
Debug
IntoIterator
PartialEq
,PartialOrd
,Eq
,Ord
Hash
AsRef
,AsMut
(both forA
and[A::Item]
)Borrow
,BorrowMut
Index
,IndexMut
Default
TryFrom
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 {}
differences:
- IntoIterator (on std's
array
IntoIterator
is implemented only on&[T; N]
and on&mut [T; N]
while on ArrayWrapper it's implemented directly (usingIterMove
)) - In some traits instead of
TryFromSliceError
there isSizeError
Copy
/Clone
are implemented only whenA: Copy/Clone
and not whenA::Item: Copy/Clone
because we can't use compiler magic :(
- IntoIterator (on std's
See Sizes Limitations paragraph in crate docs. ↩
Methods
impl<A> ArrayWrapper<A> where
A: Array,
[src]
A: Array,
pub fn new(inner: A) -> Self
[src]
Create new ArrayWrapper
use arraylib::ArrayWrapper; let arr = ArrayWrapper::new([0, 1, 2, 3]); println!("{:?}", arr);
pub fn into_inner(self) -> A
[src]
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
impl<A> Array for ArrayWrapper<A> where
A: Array,
[src]
A: Array,
Safety
ArrayWrapper
has #[repr(transparent)]
so it has the same ABI as A
.
So if A
is array then so is ArrayWrapper
.
type Item = A::Item
Type of the Items in the array. i.e. # use arraylib::Array; fn dummy<T>() where [T; 4]: Array<Item = T> # {}
Read more
type Maybe = ArrayWrapper<A::Maybe>
Same array but item is wrapped with MaybeUninit<_>
. # use arraylib::Array; fn dummy<T>() where [T; 4]: Array<Item = T, Maybe = [core::mem::MaybeUninit<T>; 4]> # {}
Read more
const SIZE: usize
[src]
fn as_slice(&self) -> &[Self::Item]
[src]
fn as_mut_slice(&mut self) -> &mut [Self::Item]
[src]
fn try_unfold<St, F, E>(init: St, f: F) -> Result<Self, E> where
F: FnMut(&mut St) -> Result<Self::Item, E>,
[src]
F: FnMut(&mut St) -> Result<Self::Item, E>,
fn unfold<St, F>(init: St, f: F) -> Self where
F: FnMut(&mut St) -> Self::Item,
[src]
F: FnMut(&mut St) -> Self::Item,
fn try_from_fn<F, E>(f: F) -> Result<Self, E> where
F: FnMut(usize) -> Result<Self::Item, E>,
[src]
F: FnMut(usize) -> Result<Self::Item, E>,
fn from_fn<F>(f: F) -> Self where
F: FnMut(usize) -> Self::Item,
[src]
F: FnMut(usize) -> Self::Item,
fn from_iter<I>(iter: I) -> Option<Self> where
I: IntoIterator<Item = Self::Item>,
[src]
I: IntoIterator<Item = Self::Item>,
fn into_uninit(self) -> Self::Maybe
[src]
fn uninit() -> Self::Maybe
[src]
unsafe fn assume_init(uninit: Self::Maybe) -> Self
[src]
fn into_boxed_slice(self) -> Box<[Self::Item]>
[src]
impl<A> AsMut<[<A as Array>::Item]> for ArrayWrapper<A> where
A: Array,
[src]
A: Array,
impl<A> AsMut<A> for ArrayWrapper<A>
[src]
impl<A> AsRef<[<A as Array>::Item]> for ArrayWrapper<A> where
A: Array,
[src]
A: Array,
impl<A> AsRef<A> for ArrayWrapper<A>
[src]
impl<A> Borrow<[<A as Array>::Item]> for ArrayWrapper<A> where
A: Array,
[src]
A: Array,
impl<A> BorrowMut<[<A as Array>::Item]> for ArrayWrapper<A> where
A: Array,
[src]
A: Array,
fn borrow_mut(&mut self) -> &mut [A::Item]
[src]
impl<A: Clone> Clone for ArrayWrapper<A>
[src]
fn clone(&self) -> ArrayWrapper<A>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: Copy> Copy for ArrayWrapper<A>
[src]
impl<A> Debug for ArrayWrapper<A> where
A::Item: Debug,
A: Array,
[src]
A::Item: Debug,
A: Array,
impl<A> Default for ArrayWrapper<A> where
A: Array,
A::Item: Default,
[src]
A: Array,
A::Item: Default,
impl<A> Eq for ArrayWrapper<A> where
A: Array,
A::Item: Eq,
[src]
A: Array,
A::Item: Eq,
impl<A> Hash for ArrayWrapper<A> where
A::Item: Hash,
A: Array,
[src]
A::Item: Hash,
A: Array,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A, Idx> Index<Idx> for ArrayWrapper<A> where
A: Array,
Idx: SliceIndex<[A::Item]>,
[src]
A: Array,
Idx: SliceIndex<[A::Item]>,
type Output = Idx::Output
The returned type after indexing.
fn index(&self, index: Idx) -> &Self::Output
[src]
impl<A, Idx> IndexMut<Idx> for ArrayWrapper<A> where
A: Array,
Idx: SliceIndex<[A::Item]>,
[src]
A: Array,
Idx: SliceIndex<[A::Item]>,
impl<A> IntoIterator for ArrayWrapper<A> where
A: Array,
[src]
A: Array,
type IntoIter = IterMove<Self>
Which kind of iterator are we turning this into?
type Item = A::Item
The type of the elements being iterated over.
fn into_iter(self) -> Self::IntoIter
[src]
impl<A> Ord for ArrayWrapper<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'t, A, T> PartialEq<&'t [T]> for ArrayWrapper<A> where
A::Item: PartialEq<T>,
A: Array,
[src]
A::Item: PartialEq<T>,
A: Array,
impl<'t, A, T> PartialEq<&'t mut [T]> for ArrayWrapper<A> where
A::Item: PartialEq<T>,
A: Array,
[src]
A::Item: PartialEq<T>,
A: Array,
fn eq(&self, other: &&'t mut [T]) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, T> PartialEq<[T]> for ArrayWrapper<A> where
A::Item: PartialEq<T>,
A: Array,
[src]
A::Item: PartialEq<T>,
A: Array,
impl<A, T> PartialEq<ArrayWrapper<A>> for [T] where
T: PartialEq<A::Item>,
A: Array,
[src]
T: PartialEq<A::Item>,
A: Array,
fn eq(&self, other: &ArrayWrapper<A>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t [T] where
T: PartialEq<A::Item>,
A: Array,
[src]
T: PartialEq<A::Item>,
A: Array,
fn eq(&self, other: &ArrayWrapper<A>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t mut [T] where
T: PartialEq<A::Item>,
A: Array,
[src]
T: PartialEq<A::Item>,
A: Array,
fn eq(&self, other: &ArrayWrapper<A>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, B> PartialEq<B> for ArrayWrapper<A> where
A::Item: PartialEq<B::Item>,
A: Array,
B: Array,
[src]
A::Item: PartialEq<B::Item>,
A: Array,
B: Array,
impl<A, B> PartialOrd<B> for ArrayWrapper<A> where
A: Array,
B: Array<Item = A::Item>,
A::Item: PartialOrd,
[src]
A: Array,
B: Array<Item = A::Item>,
A::Item: PartialOrd,
fn partial_cmp(&self, other: &B) -> Option<Ordering>
[src]
fn lt(&self, other: &B) -> bool
[src]
fn le(&self, other: &B) -> bool
[src]
fn gt(&self, other: &B) -> bool
[src]
fn ge(&self, other: &B) -> bool
[src]
impl<'_, A> TryFrom<&'_ [<A as Array>::Item]> for ArrayWrapper<A> where
A::Item: Copy,
A: Array,
[src]
A::Item: Copy,
A: Array,
type Error = SizeError
The type returned in the event of a conversion error.
fn try_from(slice: &[A::Item]) -> Result<Self, SizeError>
[src]
impl<'a, A> TryFrom<&'a [<A as Array>::Item]> for &'a ArrayWrapper<A> where
A: Array,
[src]
A: Array,
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]))
type Error = SizeError
The type returned in the event of a conversion error.
fn try_from(slice: &'a [A::Item]) -> Result<Self, SizeError>
[src]
impl<'a, A> TryFrom<&'a mut [<A as Array>::Item]> for &'a mut ArrayWrapper<A> where
A: Array,
[src]
A: Array,
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]))
Auto Trait Implementations
impl<A> Send for ArrayWrapper<A> where
A: Send,
A: Send,
impl<A> Sync for ArrayWrapper<A> where
A: Sync,
A: Sync,
impl<A> Unpin for ArrayWrapper<A> where
A: Unpin,
A: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,