use std::{
borrow::{Borrow, BorrowMut, Cow},
ops::{Deref, DerefMut, RangeBounds},
rc::Rc,
sync::Arc,
};
use crate::{BSlice, LengthExceeded, const_checks};
#[derive(Debug, Default, Hash)]
pub struct BVec<T, const MAX: usize> {
s: Vec<T>,
}
#[macro_export]
macro_rules! bvec {
() => {
$crate::BVec::new()
};
($elem:expr; $n:expr) => {{
struct _Helper<const N: usize>;
impl<const N: usize> _Helper<N> {
fn _helper<T, const MAX: usize>(s: ::std::vec::Vec<T>) -> $crate::BVec<T, MAX> {
_ = <$crate::const_checks::Pair<MAX, N> as $crate::const_checks::AssertGe>::VALID;
unsafe { $crate::BVec::from_vec_unchecked(s) }
}
}
_Helper::<$n>::_helper(::std::vec![$elem; $n])
}};
($($x:expr),+ $(,)?) => {{
struct _Helper<const N: usize>;
impl<const N: usize> _Helper<N> {
fn _helper<T, const MAX: usize>(s: ::std::vec::Vec<T>) -> $crate::BVec<T, MAX> {
_ = <$crate::const_checks::Pair<MAX, N> as $crate::const_checks::AssertGe>::VALID;
unsafe { $crate::BVec::from_vec_unchecked(s) }
}
}
const _N: usize = 0 $( + { let _ = $x; 1 })*;
_Helper::<_N>::_helper(::std::vec![$($x),+])
}};
}
impl<T, const MAX: usize> BVec<T, MAX> {
pub const unsafe fn from_vec_unchecked(s: Vec<T>) -> Self {
Self { s }
}
pub unsafe fn from_slice_unchecked(s: &[T]) -> Self
where
T: Clone,
{
Self { s: s.to_owned() }
}
pub fn from_slice(s: &[T]) -> Result<Self, LengthExceeded>
where
T: Clone,
{
BSlice::from_slice(s).map(|s| s.to_owned())
}
pub fn from_vec(s: Vec<T>) -> Result<Self, LengthExceeded> {
BSlice::<T, MAX>::from_slice(&s)?;
Ok(unsafe { Self::from_vec_unchecked(s) })
}
pub fn into_inner(self) -> Vec<T> {
self.s
}
pub const fn as_vec(&self) -> &Vec<T> {
&self.s
}
pub fn relax_max<const MAX2: usize>(self) -> BVec<T, MAX2> {
_ = <const_checks::Pair<MAX2, MAX> as const_checks::AssertGe>::VALID;
unsafe { BVec::from_vec_unchecked(self.s) }
}
pub fn change_max<const MAX2: usize>(self) -> Result<BVec<T, MAX2>, LengthExceeded> {
BVec::from_vec(self.s)
}
pub const fn as_mut_ptr(&mut self) -> *mut T {
self.s.as_mut_ptr()
}
pub const fn as_ptr(&self) -> *const T {
self.s.as_ptr()
}
pub const fn as_mut_slice(&mut self) -> &mut BSlice<T, MAX> {
unsafe { BSlice::from_slice_mut_unchecked(self.s.as_mut_slice()) }
}
pub const fn capacity(&self) -> usize {
self.s.capacity()
}
pub fn clear(&mut self) {
self.s.clear()
}
pub fn dedup_by<F>(&mut self, f: F)
where
F: FnMut(&mut T, &mut T) -> bool,
{
self.s.dedup_by(f)
}
pub fn dedup_by_key<F, K: PartialEq>(&mut self, f: F)
where
F: FnMut(&mut T) -> K,
{
self.s.dedup_by_key(f)
}
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> std::vec::Drain<T> {
self.s.drain(range)
}
pub fn extract_if<F, R: RangeBounds<usize>>(
&mut self,
range: R,
filter: F,
) -> std::vec::ExtractIf<T, F>
where
F: FnMut(&mut T) -> bool,
{
self.s.extract_if(range, filter)
}
pub fn into_boxed_slice(self) -> Box<BSlice<T, MAX>> {
unsafe { Box::from_raw(Box::into_raw(self.s.into_boxed_slice()) as *mut BSlice<T, MAX>) }
}
pub fn leak<'a>(self) -> &'a mut BSlice<T, MAX> {
unsafe { BSlice::from_slice_mut_unchecked(self.s.leak()) }
}
pub fn new() -> Self {
Self { s: Vec::new() }
}
pub fn pop(&mut self) -> Option<T> {
self.s.pop()
}
pub fn pop_if(&mut self, f: impl FnOnce(&mut T) -> bool) -> Option<T> {
self.s.pop_if(f)
}
pub fn remove(&mut self, idx: usize) -> T {
self.s.remove(idx)
}
pub fn reserve(&mut self, additional: usize) {
self.s.reserve(additional)
}
pub fn reserve_exact(&mut self, additional: usize) {
self.s.reserve_exact(additional)
}
pub fn retain(&mut self, f: impl FnMut(&T) -> bool) {
self.s.retain(f)
}
pub fn retain_mut(&mut self, f: impl FnMut(&mut T) -> bool) {
self.s.retain_mut(f)
}
pub fn shrink_to(&mut self, min_capacity: usize) {
self.s.shrink_to(min_capacity)
}
pub fn shrink_to_fit(&mut self) {
self.s.shrink_to_fit()
}
pub fn spare_capacity_mut(&mut self) -> &mut [std::mem::MaybeUninit<T>] {
self.s.spare_capacity_mut()
}
pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> std::vec::Splice<I::IntoIter>
where
R: RangeBounds<usize>,
I: IntoIterator<Item = T>,
{
self.s.splice(range, replace_with)
}
pub fn split_off(&mut self, idx: usize) -> BVec<T, MAX> {
unsafe { BVec::from_vec_unchecked(self.s.split_off(idx)) }
}
pub fn swap_remove(&mut self, idx: usize) -> T {
self.s.swap_remove(idx)
}
pub fn truncate(&mut self, len: usize) {
self.s.truncate(len)
}
pub fn try_reserve(
&mut self,
additional: usize,
) -> Result<(), std::collections::TryReserveError> {
self.s.try_reserve(additional)
}
pub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), std::collections::TryReserveError> {
self.s.try_reserve_exact(additional)
}
pub fn with_capacity(capacity: usize) -> Self {
Self {
s: Vec::with_capacity(capacity),
}
}
}
impl<T: PartialEq, const MAX: usize> BVec<T, MAX> {
pub fn dedup(&mut self) {
self.s.dedup()
}
}
impl<T, const MAX: usize> Deref for BVec<T, MAX> {
type Target = BSlice<T, MAX>;
fn deref(&self) -> &Self::Target {
unsafe { BSlice::from_slice_unchecked(&self.s) }
}
}
impl<T, const MAX: usize> DerefMut for BVec<T, MAX> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { BSlice::from_slice_mut_unchecked(&mut self.s) }
}
}
impl<T, const MAX: usize> Borrow<BSlice<T, MAX>> for BVec<T, MAX> {
fn borrow(&self) -> &BSlice<T, MAX> {
self
}
}
impl<T, const MAX: usize> BorrowMut<BSlice<T, MAX>> for BVec<T, MAX> {
fn borrow_mut(&mut self) -> &mut BSlice<T, MAX> {
self
}
}
impl<T, const MAX: usize> AsRef<BSlice<T, MAX>> for BVec<T, MAX> {
fn as_ref(&self) -> &BSlice<T, MAX> {
self
}
}
impl<T, const MAX: usize> AsMut<BSlice<T, MAX>> for BVec<T, MAX> {
fn as_mut(&mut self) -> &mut BSlice<T, MAX> {
self
}
}
impl<T, const MAX: usize> From<BVec<T, MAX>> for Box<BSlice<T, MAX>> {
fn from(value: BVec<T, MAX>) -> Self {
let b = Box::<[T]>::from(value.s);
unsafe { Box::from_raw(Box::into_raw(b) as *mut BSlice<T, MAX>) }
}
}
impl<T: PartialEq<U>, U, const MAX1: usize, const MAX2: usize> PartialEq<BSlice<U, MAX2>>
for BVec<T, MAX1>
{
fn eq(&self, other: &BSlice<U, MAX2>) -> bool {
(***self).eq(&**other)
}
}
impl<T: PartialEq<U>, U, const MAX1: usize, const MAX2: usize> PartialEq<&BSlice<U, MAX2>>
for BVec<T, MAX1>
{
fn eq(&self, other: &&BSlice<U, MAX2>) -> bool {
(***self).eq(&***other)
}
}
impl<T: PartialEq<U>, U, const MAX1: usize, const MAX2: usize> PartialEq<&mut BSlice<U, MAX2>>
for BVec<T, MAX1>
{
fn eq(&self, other: &&mut BSlice<U, MAX2>) -> bool {
(***self).eq(&***other)
}
}
impl<T, const MAX: usize> AsRef<BVec<T, MAX>> for BVec<T, MAX> {
fn as_ref(&self) -> &BVec<T, MAX> {
self
}
}
impl<T, const MAX: usize> AsRef<Vec<T>> for BVec<T, MAX> {
fn as_ref(&self) -> &Vec<T> {
&self.s
}
}
impl<T, const MAX: usize> AsMut<BVec<T, MAX>> for BVec<T, MAX> {
fn as_mut(&mut self) -> &mut BVec<T, MAX> {
self
}
}
impl<T, const MAX: usize> AsRef<[T]> for BVec<T, MAX> {
fn as_ref(&self) -> &[T] {
self
}
}
impl<T, const MAX: usize> AsMut<[T]> for BVec<T, MAX> {
fn as_mut(&mut self) -> &mut [T] {
self
}
}
impl<T, const MAX: usize> Borrow<[T]> for BVec<T, MAX> {
fn borrow(&self) -> &[T] {
self
}
}
impl<T, const MAX: usize> BorrowMut<[T]> for BVec<T, MAX> {
fn borrow_mut(&mut self) -> &mut [T] {
self
}
}
impl<T: Clone, const MAX: usize> Clone for BVec<T, MAX> {
fn clone(&self) -> Self {
Self { s: self.s.clone() }
}
}
impl<'a, T: Clone, const MAX: usize> From<&'a BVec<T, MAX>> for Cow<'a, BSlice<T, MAX>> {
fn from(value: &'a BVec<T, MAX>) -> Self {
Self::Borrowed(value)
}
}
impl<T: Clone, const MAX: usize> From<BVec<T, MAX>> for Cow<'_, BSlice<T, MAX>> {
fn from(value: BVec<T, MAX>) -> Self {
Self::Owned(value)
}
}
impl<const MAX: usize> From<BVec<std::num::NonZero<u8>, MAX>> for std::ffi::CString {
fn from(value: BVec<std::num::NonZero<u8>, MAX>) -> Self {
value.s.into()
}
}
impl<T, const MAX: usize> From<BVec<T, MAX>> for Arc<BSlice<T, MAX>> {
fn from(value: BVec<T, MAX>) -> Self {
unsafe { Arc::from_raw(Arc::into_raw(Arc::<[T]>::from(value.s)) as *const BSlice<T, MAX>) }
}
}
impl<T: Ord, const MAX: usize> From<BVec<T, MAX>> for std::collections::BinaryHeap<T> {
fn from(value: BVec<T, MAX>) -> Self {
value.s.into()
}
}
impl<T, const MAX: usize> From<BVec<T, MAX>> for Rc<BSlice<T, MAX>> {
fn from(value: BVec<T, MAX>) -> Self {
unsafe { Rc::from_raw(Rc::into_raw(Rc::<[T]>::from(value.s)) as *const BSlice<T, MAX>) }
}
}
impl<T, const MAX: usize> From<BVec<T, MAX>> for std::collections::VecDeque<T> {
fn from(value: BVec<T, MAX>) -> Self {
value.s.into()
}
}
impl<T, const MAX: usize> IntoIterator for BVec<T, MAX> {
type Item = T;
type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.s.into_iter()
}
}
impl<'a, T, const MAX: usize> IntoIterator for &'a BVec<T, MAX> {
type Item = &'a T;
type IntoIter = <&'a Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&self.s).into_iter()
}
}
impl<'a, T, const MAX: usize> IntoIterator for &'a mut BVec<T, MAX> {
type Item = &'a mut T;
type IntoIter = <&'a mut Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&mut self.s).into_iter()
}
}
impl<T: PartialEq<U>, U, const MAX1: usize, const MAX2: usize> PartialEq<BVec<U, MAX2>>
for BVec<T, MAX1>
{
fn eq(&self, other: &BVec<U, MAX2>) -> bool {
(***self).eq(&**other)
}
}
impl<T: PartialEq<U>, U, const MAX1: usize, const MAX2: usize> PartialEq<&BVec<U, MAX2>>
for BVec<T, MAX1>
{
fn eq(&self, other: &&BVec<U, MAX2>) -> bool {
(***self).eq(&**other)
}
}
impl<T: PartialEq<U>, U, const MAX1: usize, const MAX2: usize> PartialEq<&mut BVec<U, MAX2>>
for BVec<T, MAX1>
{
fn eq(&self, other: &&mut BVec<U, MAX2>) -> bool {
(***self).eq(&**other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize> PartialEq<[U]> for BVec<T, MAX> {
fn eq(&self, other: &[U]) -> bool {
(**self).eq(other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize> PartialEq<[U]> for &BVec<T, MAX> {
fn eq(&self, other: &[U]) -> bool {
(**self).eq(other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize> PartialEq<[U]> for &mut BVec<T, MAX> {
fn eq(&self, other: &[U]) -> bool {
(**self).eq(other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize> PartialEq<BVec<T, MAX>> for [U] {
fn eq(&self, other: &BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize> PartialEq<&BVec<T, MAX>> for [U] {
fn eq(&self, other: &&BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize> PartialEq<&mut BVec<T, MAX>> for [U] {
fn eq(&self, other: &&mut BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize, const N: usize> PartialEq<[U; N]> for BVec<T, MAX> {
fn eq(&self, other: &[U; N]) -> bool {
(**self).eq(other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize, const N: usize> PartialEq<[U; N]> for &BVec<T, MAX> {
fn eq(&self, other: &[U; N]) -> bool {
(**self).eq(other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize, const N: usize> PartialEq<[U; N]> for &mut BVec<T, MAX> {
fn eq(&self, other: &[U; N]) -> bool {
(**self).eq(other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize, const N: usize> PartialEq<BVec<T, MAX>> for [U; N] {
fn eq(&self, other: &BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize, const N: usize> PartialEq<&BVec<T, MAX>> for [U; N] {
fn eq(&self, other: &&BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize, const N: usize> PartialEq<&mut BVec<T, MAX>> for [U; N] {
fn eq(&self, other: &&mut BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize> PartialEq<Vec<U>> for BVec<T, MAX> {
fn eq(&self, other: &Vec<U>) -> bool {
(**self).eq(other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize> PartialEq<Vec<U>> for &BVec<T, MAX> {
fn eq(&self, other: &Vec<U>) -> bool {
(**self).eq(other)
}
}
impl<T: PartialEq<U>, U, const MAX: usize> PartialEq<Vec<U>> for &mut BVec<T, MAX> {
fn eq(&self, other: &Vec<U>) -> bool {
(**self).eq(other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize> PartialEq<BVec<T, MAX>> for Vec<U> {
fn eq(&self, other: &BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize> PartialEq<&BVec<T, MAX>> for Vec<U> {
fn eq(&self, other: &&BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T, U: PartialEq<T>, const MAX: usize> PartialEq<&mut BVec<T, MAX>> for Vec<U> {
fn eq(&self, other: &&mut BVec<T, MAX>) -> bool {
self.eq(&**other)
}
}
impl<T: PartialEq<U>, U: Clone, const MAX: usize> PartialEq<Cow<'_, [U]>> for BVec<T, MAX> {
fn eq(&self, other: &Cow<'_, [U]>) -> bool {
(**self).eq(&**other)
}
}
impl<T: PartialEq<U>, U: Clone, const MAX: usize> PartialEq<Cow<'_, [U]>> for &BVec<T, MAX> {
fn eq(&self, other: &Cow<'_, [U]>) -> bool {
(**self).eq(&**other)
}
}
impl<T: PartialEq<U>, U: Clone, const MAX: usize> PartialEq<Cow<'_, [U]>> for &mut BVec<T, MAX> {
fn eq(&self, other: &Cow<'_, [U]>) -> bool {
(**self).eq(&**other)
}
}
impl<T, U: PartialEq<T> + Clone, const MAX: usize> PartialEq<BVec<T, MAX>> for Cow<'_, [U]> {
fn eq(&self, other: &BVec<T, MAX>) -> bool {
(**self).eq(&***other)
}
}
impl<T, U: PartialEq<T> + Clone, const MAX: usize> PartialEq<&BVec<T, MAX>> for Cow<'_, [U]> {
fn eq(&self, other: &&BVec<T, MAX>) -> bool {
(**self).eq(&***other)
}
}
impl<T, U: PartialEq<T> + Clone, const MAX: usize> PartialEq<&mut BVec<T, MAX>> for Cow<'_, [U]> {
fn eq(&self, other: &&mut BVec<T, MAX>) -> bool {
(**self).eq(&***other)
}
}
impl<T: PartialEq<U>, U: Clone, const MAX: usize, const MAX2: usize>
PartialEq<Cow<'_, BSlice<U, MAX2>>> for BVec<T, MAX>
{
fn eq(&self, other: &Cow<'_, BSlice<U, MAX2>>) -> bool {
(**self).eq(&**other)
}
}
impl<T: PartialEq<U>, U: Clone, const MAX: usize, const MAX2: usize>
PartialEq<Cow<'_, BSlice<U, MAX2>>> for &BVec<T, MAX>
{
fn eq(&self, other: &Cow<'_, BSlice<U, MAX2>>) -> bool {
(**self).eq(&***other)
}
}
impl<T: PartialEq<U>, U: Clone, const MAX: usize, const MAX2: usize>
PartialEq<Cow<'_, BSlice<U, MAX2>>> for &mut BVec<T, MAX>
{
fn eq(&self, other: &Cow<'_, BSlice<U, MAX2>>) -> bool {
(**self).eq(&***other)
}
}
impl<T, U: PartialEq<T> + Clone, const MAX: usize, const MAX2: usize> PartialEq<BVec<T, MAX>>
for Cow<'_, BSlice<U, MAX2>>
{
fn eq(&self, other: &BVec<T, MAX>) -> bool {
(**self).eq(&**other)
}
}
impl<T, U: PartialEq<T> + Clone, const MAX: usize, const MAX2: usize> PartialEq<&BVec<T, MAX>>
for Cow<'_, BSlice<U, MAX2>>
{
fn eq(&self, other: &&BVec<T, MAX>) -> bool {
(**self).eq(&**other)
}
}
impl<T, U: PartialEq<T> + Clone, const MAX: usize, const MAX2: usize> PartialEq<&mut BVec<T, MAX>>
for Cow<'_, BSlice<U, MAX2>>
{
fn eq(&self, other: &&mut BVec<T, MAX>) -> bool {
(**self).eq(&**other)
}
}
impl<T: Eq, const MAX: usize> Eq for BVec<T, MAX> {}
impl<T: PartialOrd, const MAX: usize, const MAX2: usize> PartialOrd<BVec<T, MAX2>>
for BVec<T, MAX>
{
fn partial_cmp(&self, other: &BVec<T, MAX2>) -> Option<std::cmp::Ordering> {
(**self).partial_cmp(other)
}
}
impl<T: Ord, const MAX: usize> Ord for BVec<T, MAX> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(**self).cmp(other)
}
}
impl<T, const MAX: usize> TryFrom<Vec<T>> for BVec<T, MAX> {
type Error = LengthExceeded;
fn try_from(value: Vec<T>) -> Result<Self, Self::Error> {
Self::from_vec(value)
}
}
impl<T: Clone, const MAX: usize> TryFrom<&[T]> for BVec<T, MAX> {
type Error = LengthExceeded;
fn try_from(value: &[T]) -> Result<Self, Self::Error> {
Self::from_slice(value)
}
}
impl<T: Clone, const MAX: usize> TryFrom<&mut [T]> for BVec<T, MAX> {
type Error = LengthExceeded;
fn try_from(value: &mut [T]) -> Result<Self, Self::Error> {
Self::from_slice(value)
}
}
impl<T, const MAX: usize, const N: usize> TryFrom<BVec<T, MAX>> for [T; N] {
type Error = BVec<T, MAX>;
fn try_from(value: BVec<T, MAX>) -> Result<Self, Self::Error> {
<[T; N]>::try_from(value.s).map_err(|v| unsafe { BVec::from_vec_unchecked(v) })
}
}
impl<T, const MAX: usize, const N: usize> TryFrom<BVec<T, MAX>> for Box<[T; N]> {
type Error = BVec<T, MAX>;
fn try_from(value: BVec<T, MAX>) -> Result<Self, Self::Error> {
Box::<[T; N]>::try_from(value.s).map_err(|v| unsafe { BVec::from_vec_unchecked(v) })
}
}
impl<const MAX: usize> TryFrom<BVec<u8, MAX>> for String {
type Error = std::string::FromUtf8Error;
fn try_from(value: BVec<u8, MAX>) -> Result<Self, Self::Error> {
String::try_from(value.s)
}
}
#[cfg(feature = "serde")]
mod serde_impls {
use std::marker::PhantomData;
use super::*;
use serde::{
Deserialize, Serialize,
de::{SeqAccess, Visitor},
ser::SerializeSeq,
};
impl<T: Serialize, const MAX: usize> Serialize for BVec<T, MAX> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut seq = serializer.serialize_seq(Some(self.len()))?;
for e in self {
seq.serialize_element(e)?;
}
seq.end()
}
}
struct BVecVisitor<T, const MAX: usize>(PhantomData<fn(T) -> T>);
impl<'de, T: Deserialize<'de>, const MAX: usize> Visitor<'de> for BVecVisitor<T, MAX> {
type Value = BVec<T, MAX>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a sequence")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut vec = Vec::new();
while let Some(e) = seq.next_element()? {
vec.push(e);
}
let len = vec.len();
match BVec::from_vec(vec) {
Ok(bvec) => Ok(bvec),
Err(_e) => Err(serde::de::Error::invalid_length(
len,
&format!("{MAX}").as_str(),
)),
}
}
}
impl<'de, T: Deserialize<'de>, const MAX: usize> Deserialize<'de> for BVec<T, MAX> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_seq(BVecVisitor(PhantomData))
}
}
}
#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn test_bvec_macro() {
let _: BVec<u8, 255> = bvec![];
let _: BVec<_, 255> = bvec![0; 20];
let _: BVec<_, 255> = bvec![0, 1, 2, 3, 4];
}
}