pub struct Lobby<T, const N: usize> { /* private fields */ }
Expand description
A const-size queue-like data structure.
Implementations§
Source§impl<T, const N: usize> Lobby<T, N>
impl<T, const N: usize> Lobby<T, N>
Sourcepub const fn first(&self) -> Option<&T>
pub const fn first(&self) -> Option<&T>
Get the head item.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
assert_eq!(None, lobby.first());
lobby.push(0);
assert_eq!(Some(&0), lobby.first());
lobby.push(1);
assert_eq!(Some(&0), lobby.first());
Sourcepub fn first_mut(&mut self) -> Option<&mut T>
pub fn first_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the head item. See Self::first
.
Sourcepub const fn last(&self) -> Option<&T>
pub const fn last(&self) -> Option<&T>
Get the tail item.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
assert_eq!(None, lobby.last());
lobby.push(0);
assert_eq!(Some(&0), lobby.last());
lobby.push(1);
assert_eq!(Some(&1), lobby.last());
Sourcepub fn last_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the head item. See Self::last
.
Sourcepub const fn nth(&self, n: usize) -> Option<&T>
pub const fn nth(&self, n: usize) -> Option<&T>
Get the nth item.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
assert_eq!(None, lobby.nth(1));
lobby.push(0);
assert_eq!(None, lobby.nth(1));
lobby.push(1);
assert_eq!(Some(&1), lobby.nth(1));
§Panics
Panics if n
is greater than or equal to N
.
ⓘ
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
lobby.push(0);
let _ = lobby.nth(3);
Sourcepub fn push(&mut self, v: T) -> Option<T>
pub fn push(&mut self, v: T) -> Option<T>
Push a new item to the lobby, returning the head if the lobby is currently full.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
lobby.push(0);
assert_eq!(Some(&0), lobby.first());
lobby.push(1);
assert_eq!(Some(&0), lobby.first());
lobby.push(2);
assert_eq!(Some(&0), lobby.first());
lobby.push(3);
assert_eq!(Some(&1), lobby.first());
Sourcepub fn shift(&mut self) -> Option<T>
pub fn shift(&mut self) -> Option<T>
Shift out the head item from the lobby.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
lobby.push(0);
lobby.push(1);
lobby.push(2);
assert_eq!(Some(0), lobby.shift());
assert_eq!(Some(1), lobby.shift());
assert_eq!(Some(2), lobby.shift());
assert_eq!(None, lobby.shift());
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Pop off the tail item from the lobby.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
lobby.push(0);
lobby.push(1);
lobby.push(2);
assert_eq!(Some(2), lobby.pop());
assert_eq!(Some(1), lobby.pop());
assert_eq!(Some(0), lobby.pop());
assert_eq!(None, lobby.pop());
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the Lobby is empty, false
if it is not.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
assert!(lobby.is_empty());
lobby.push(0);
assert!(!lobby.is_empty());
lobby.shift();
assert!(lobby.is_empty());
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the Lobby is full, false
if it is not.
use lobby_queue::Lobby;
let mut lobby = Lobby::new([None, None, None]);
assert!(!lobby.is_full());
lobby.push(0);
assert!(!lobby.is_full());
lobby.push(1);
assert!(!lobby.is_full());
lobby.push(2);
assert!(lobby.is_full());
Trait Implementations§
Source§impl<T, const N: usize> IntoIterator for Lobby<T, N>
impl<T, const N: usize> IntoIterator for Lobby<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for Lobby<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for Lobby<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for Lobby<T, N>where
T: Send,
impl<T, const N: usize> Sync for Lobby<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for Lobby<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for Lobby<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