pub struct PinArray<T, const SIZE: usize> { /* private fields */ }Expand description
A structurally pinned array of values
Implementations§
source§impl<T, const SIZE: usize> PinArray<T, SIZE>
impl<T, const SIZE: usize> PinArray<T, SIZE>
sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Get the length of the PinArray
assert_eq!(PinArray::new(['a', 'b', 'c']).len(), 3);sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Check if the array is empty
assert!(PinArray::<u32, 0>::new([]).is_empty());sourcepub fn get(&self, idx: usize) -> Option<&T>
pub fn get(&self, idx: usize) -> Option<&T>
Attempt to get a reference to an element by index
Note this does not require Pin as a reference is trivially
Unpin
let p = pin!(PinArray::new([1, 2, 3]));
assert_eq!(p.get(0), Some(&1));
assert_eq!(p.get(1), Some(&2));
assert_eq!(p.get(2), Some(&3));sourcepub fn get_pin(self: Pin<&mut Self>, idx: usize) -> Option<Pin<&mut T>>
pub fn get_pin(self: Pin<&mut Self>, idx: usize) -> Option<Pin<&mut T>>
Attempt to get a pinned reference to an element by index
Note this requires self to be pinned
let mut p = pin!(PinArray::new([1, 2, 3]));
assert_eq!(p.as_mut().get_pin(0), Some(Pin::new(&mut 1)));
assert_eq!(p.as_mut().get_pin(1), Some(Pin::new(&mut 2)));
assert_eq!(p.as_mut().get_pin(2), Some(Pin::new(&mut 3)));sourcepub fn as_ref_array(&self) -> [&T; SIZE]
pub fn as_ref_array(&self) -> [&T; SIZE]
Convert this PinArray to an array of references
Immutable counterpart to PinArray::as_pin_array
let p = pin!(PinArray::new(["a", "b"]));
assert_eq!(p.as_ref_array(), [&"a", &"b"]);sourcepub fn as_pin_array<'me>(self: Pin<&'me mut Self>) -> [Pin<&'me mut T>; SIZE]
pub fn as_pin_array<'me>(self: Pin<&'me mut Self>) -> [Pin<&'me mut T>; SIZE]
Convert this pinned PinArray to an array of pinned mutable references
Mutable counterpart to PinArray::as_ref_array
let mut p = pin!(PinArray::new(["a", "b"]));
assert_eq!(p.as_pin_array(), [Pin::new(&mut "a"), Pin::new(&mut "b")]);sourcepub fn iter(&self) -> Iter<'_, T, SIZE> ⓘ
pub fn iter(&self) -> Iter<'_, T, SIZE> ⓘ
Get an iterator over references to the elements
let p = pin!(PinArray::new(['h', 'i']));
let mut i = p.iter();
assert_eq!(i.next(), Some(&'h'));
assert_eq!(i.next(), Some(&'i'));
assert_eq!(i.next(), None);sourcepub fn iter_mut(self: Pin<&mut Self>) -> IterMut<'_, T, SIZE> ⓘ
pub fn iter_mut(self: Pin<&mut Self>) -> IterMut<'_, T, SIZE> ⓘ
Get an iterator over pinned mutable references to the elements
let mut p = pin!(PinArray::new(['h', 'i']));
let mut i = p.iter_mut();
assert_eq!(i.next(), Some(Pin::new(&mut 'h')));
assert_eq!(i.next(), Some(Pin::new(&mut 'i')));
assert_eq!(i.next(), None);Trait Implementations§
source§impl<T: Ord, const SIZE: usize> Ord for PinArray<T, SIZE>
impl<T: Ord, const SIZE: usize> Ord for PinArray<T, SIZE>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<T: PartialEq, const SIZE: usize> PartialEq for PinArray<T, SIZE>
impl<T: PartialEq, const SIZE: usize> PartialEq for PinArray<T, SIZE>
source§impl<T: PartialOrd, const SIZE: usize> PartialOrd for PinArray<T, SIZE>
impl<T: PartialOrd, const SIZE: usize> PartialOrd for PinArray<T, SIZE>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl<T: Copy, const SIZE: usize> Copy for PinArray<T, SIZE>
impl<T: Eq, const SIZE: usize> Eq for PinArray<T, SIZE>
impl<T, const SIZE: usize> StructuralPartialEq for PinArray<T, SIZE>
impl<T: Unpin, const SIZE: usize> Unpin for PinArray<T, SIZE>
Auto Trait Implementations§
impl<T, const SIZE: usize> RefUnwindSafe for PinArray<T, SIZE>where
T: RefUnwindSafe,
impl<T, const SIZE: usize> Send for PinArray<T, SIZE>where
T: Send,
impl<T, const SIZE: usize> Sync for PinArray<T, SIZE>where
T: Sync,
impl<T, const SIZE: usize> UnwindSafe for PinArray<T, SIZE>where
T: UnwindSafe,
Blanket Implementations§
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