panic if queue is too big

This commit is contained in:
tali 2023-04-16 03:46:49 -04:00
parent e15637f0dd
commit 588d673ad0
1 changed files with 4 additions and 0 deletions

View File

@ -12,6 +12,10 @@ pub struct Queue<'a, T: Copy> {
impl<'a, T: Copy> Queue<'a, T> { impl<'a, T: Copy> Queue<'a, T> {
/// Constructs a new queue. /// Constructs a new queue.
pub const fn new(mut hold: Option<T>, mut next: &'a [T]) -> Self { pub const fn new(mut hold: Option<T>, mut next: &'a [T]) -> Self {
if next.len() + 1 > u16::MAX as usize {
panic!("too many elements in queue");
}
// SIGH. so `hold.is_none()` is not valid in `const fn`, for some obscure reason. // SIGH. so `hold.is_none()` is not valid in `const fn`, for some obscure reason.
#[allow(clippy::redundant_pattern_matching)] #[allow(clippy::redundant_pattern_matching)]
if let None = hold { if let None = hold {