pub struct Array<T, const N: usize> { /* private fields */ }Expand description
An array type like [T; N], but providing some methods of Vec.
Implementations§
Source§impl<T, const N: usize> Array<T, N>
impl<T, const N: usize> Array<T, N>
Sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Returns capacity, which is N.
§Examples
use my_ecs::ds::Array;
let arr = Array::<i32, 2>::new();
assert_eq!(arr.capacity(), 2);Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns number of items.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
assert_eq!(arr.len(), 1);Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true if the array is empty.
§Examples
use my_ecs::ds::Array;
let arr = Array::<i32, 2>::new();
assert!(arr.is_empty());Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true if the array contains N items.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
arr.push(1);
assert!(arr.is_full());Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Retrieves a shared reference to an item at the given index.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
assert_eq!(arr.get(0), Some(&0));Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Retrieves a mutable reference to an item at the given index.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
assert_eq!(arr.get_mut(0), Some(&mut 0));Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns iterator traversing all items.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
arr.push(1);
for item in arr.iter() {
println!("{item}");
}Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns mutable iterator traversing all items.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
arr.push(1);
for item in arr.iter_mut() {
*item += 1;
}Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns &[T] from the array.
§Examples
use my_ecs::ds::Array;
let arr = Array::<i32, 2>::new();
let slice: &[i32] = arr.as_slice();Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns &mut [T] from the array.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
let slice: &mut [i32] = arr.as_mut_slice();Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all items in the array.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
arr.clear();
assert!(arr.is_empty());Sourcepub fn push(&mut self, value: T) -> bool
pub fn push(&mut self, value: T) -> bool
Appends a given item at the end of the array.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Takes out an item from the end of the array.
§Examples
use my_ecs::ds::Array;
let mut arr = Array::<i32, 2>::new();
arr.push(0);
arr.push(1);
assert_eq!(arr.pop(), Some(1));
assert_eq!(arr.pop(), Some(0));Trait Implementations§
Auto Trait Implementations§
impl<T, const N: usize> Freeze for Array<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for Array<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for Array<T, N>where
T: Send,
impl<T, const N: usize> Sync for Array<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for Array<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for Array<T, N>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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more