use std::num;
use o3::buffer::bytes;
use crate::wire::{
self,
receive::{self, batch, batch::Capacity},
};
pub unsafe trait Batch<'input> {
type Item: bytes::TryRetain + 'input;
const MAX_ITEMS: num::NonZero<usize> = num::NonZero::<usize>::MIN;
const MIN_CAPACITY: num::NonZero<usize> = Self::MAX_ITEMS;
fn len(&self) -> usize;
fn next(&mut self) -> Option<Self::Item>;
}
pub unsafe trait Producer<'input, W: wire::Spec + 'input> {
fn produce(
self,
capacity: &Capacity<'_, W>,
) -> <W::Receive as receive::Policy<W>>::Batch<'input>;
}
unsafe impl<'input, T: bytes::TryRetain + 'input> receive::raw::Batch<'input> for batch::One<T> {
type Item = T;
fn len(&self) -> usize {
usize::from(self.item.is_some())
}
fn next(&mut self) -> Option<Self::Item> {
self.item.take()
}
}