pub mod raw;
mod sealed;
use std::{marker, num};
use crate::wire;
pub struct Capacity<W: wire::Wire> {
items: num::NonZeroUsize,
wire: marker::PhantomData<fn() -> W>,
}
impl<W: wire::Wire> Capacity<W> {
pub fn fit(available: usize) -> Option<Self> {
let min = <W::RecvBatch<'static> as raw::Source>::MIN_CAPACITY;
let max = <W::RecvBatch<'static> as raw::Source>::MAX_ITEMS;
if min > max {
return None;
}
let items = num::NonZeroUsize::new(available.min(max.get()))?;
(items >= min).then_some(Self {
items,
wire: marker::PhantomData,
})
}
pub fn full() -> Self {
Self {
items: <W::RecvBatch<'static> as raw::Source>::MAX_ITEMS,
wire: marker::PhantomData,
}
}
pub fn items(&self) -> num::NonZeroUsize {
self.items
}
}