#![forbid(unsafe_code)]
use super::*;
use core::cmp::Ordering;
impl<T, const N: usize> Default for FixedCapacityVec<T, N> {
fn default() -> Self {
Self::new()
}
}
impl<T, const N: usize> Debug for FixedCapacityVec<T, N>
where
T: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.deref().fmt(f)
}
}
impl<T, const N: usize> Clone for FixedCapacityVec<T, N>
where
T: Clone,
{
fn clone(&self) -> Self {
let mut out = Self::new();
for item in &**self {
out.push(item.clone())
}
out
}
}
impl<T, const N: usize> Hash for FixedCapacityVec<T, N>
where
T: Hash,
{
fn hash<H>(&self, h: &mut H)
where
H: std::hash::Hasher,
{
(**self).hash(h)
}
}
macro_rules! impl_comparison_trait { { $Trait:ident $( $fn:ident $result:ty )? } => {
impl<T, const N: usize> $Trait for FixedCapacityVec<T, N>
where
T: $Trait,
{
$(
fn $fn(&self, other: &Self) -> $result {
(**self).$fn(&**other)
}
)?
}
} }
impl_comparison_trait! { PartialEq eq bool }
impl_comparison_trait! { PartialOrd partial_cmp Option<Ordering> }
impl_comparison_trait! { Ord cmp Ordering }
impl_comparison_trait! { Eq }
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct FullError;
impl Display for FullError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt("pushed to a full FixedCapacityVec", f)
}
}