[][src]Struct arraylib::ArrayWrapper

#[repr(transparent)]
pub struct ArrayWrapper<A> { /* fields omitted */ }

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:

Note: Implementations of the most trai just copy-pasted from std

Examples

PartialEq/Eq :

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 {}

  1. 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 (using IterMove))
    • In some traits instead of TryFromSliceError there is SizeError
    • Copy/Clone are implemented only when A: Copy/Clone and not when A::Item: Copy/Clone because we can't use compiler magic :(
     
  2. See Sizes Limitations paragraph in crate docs. 

Methods

impl<A> ArrayWrapper<A> where
    A: Array
[src]

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]

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

impl<A> AsMut<[<A as Array>::Item]> for ArrayWrapper<A> where
    A: Array
[src]

impl<A> AsMut<A> for ArrayWrapper<A>[src]

impl<A> AsRef<[<A as Array>::Item]> for ArrayWrapper<A> where
    A: Array
[src]

impl<A> AsRef<A> for ArrayWrapper<A>[src]

impl<A> Borrow<[<A as Array>::Item]> for ArrayWrapper<A> where
    A: Array
[src]

impl<A> BorrowMut<[<A as Array>::Item]> for ArrayWrapper<A> where
    A: Array
[src]

impl<A: Clone> Clone for ArrayWrapper<A>[src]

impl<A: Copy> Copy for ArrayWrapper<A>[src]

impl<A> Debug for ArrayWrapper<A> where
    A::Item: Debug,
    A: Array
[src]

impl<A> Default for ArrayWrapper<A> where
    A: Array,
    A::Item: Default
[src]

impl<A> Eq for ArrayWrapper<A> where
    A: Array,
    A::Item: Eq
[src]

impl<A> Hash for ArrayWrapper<A> where
    A::Item: Hash,
    A: Array
[src]

impl<A, Idx> Index<Idx> for ArrayWrapper<A> where
    A: Array,
    Idx: SliceIndex<[A::Item]>, 
[src]

type Output = Idx::Output

The returned type after indexing.

impl<A, Idx> IndexMut<Idx> for ArrayWrapper<A> where
    A: Array,
    Idx: SliceIndex<[A::Item]>, 
[src]

impl<A> IntoIterator for ArrayWrapper<A> where
    A: Array
[src]

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.

impl<A> Ord for ArrayWrapper<A> where
    A: Array,
    A::Item: Ord
[src]

impl<'t, A, T> PartialEq<&'t [T]> for ArrayWrapper<A> where
    A::Item: PartialEq<T>,
    A: Array
[src]

impl<'t, A, T> PartialEq<&'t mut [T]> for ArrayWrapper<A> where
    A::Item: PartialEq<T>,
    A: Array
[src]

impl<A, T> PartialEq<[T]> for ArrayWrapper<A> where
    A::Item: PartialEq<T>,
    A: Array
[src]

impl<A, T> PartialEq<ArrayWrapper<A>> for [T] where
    T: PartialEq<A::Item>,
    A: Array
[src]

impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t [T] where
    T: PartialEq<A::Item>,
    A: Array
[src]

impl<'t, A, T> PartialEq<ArrayWrapper<A>> for &'t mut [T] where
    T: PartialEq<A::Item>,
    A: Array
[src]

impl<A, B> PartialEq<B> for ArrayWrapper<A> where
    A::Item: PartialEq<B::Item>,
    A: Array,
    B: Array
[src]

impl<A, B> PartialOrd<B> for ArrayWrapper<A> where
    A: Array,
    B: Array<Item = A::Item>,
    A::Item: PartialOrd
[src]

impl<'_, A> TryFrom<&'_ [<A as Array>::Item]> for ArrayWrapper<A> where
    A::Item: Copy,
    A: Array
[src]

type Error = SizeError

The type returned in the event of a conversion error.

impl<'a, A> TryFrom<&'a [<A as Array>::Item]> for &'a ArrayWrapper<A> where
    A: Array
[src]

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.

impl<'a, A> TryFrom<&'a mut [<A as Array>::Item]> for &'a mut ArrayWrapper<A> where
    A: Array
[src]

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]))

type Error = SizeError

The type returned in the event of a conversion error.

Auto Trait Implementations

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

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?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.