o3 0.36.2

shared-nothing primitives
Documentation
use buffer::Read as _;

use crate::{
    buffer,
    buffer::{resident, write::consume},
};

#[must_use]
pub struct Deferred<'input, 'd, R: buffer::Source + 'input> {
    pub(in crate::buffer::hold) input: (R::View<'input>, &'input resident::Budget<'d>),
}

impl<'input, 'd, R: buffer::Source + 'input> Deferred<'input, 'd, R> {
    pub fn as_slice(&self) -> &'input [u8] {
        self.input.0.as_slice()
    }

    pub const fn budget(&self) -> &'input resident::Budget<'d> {
        self.input.1
    }

    pub fn len(&self) -> usize {
        self.as_slice().len()
    }

    pub fn is_empty(&self) -> bool {
        self.as_slice().is_empty()
    }

    pub fn try_split<const N: usize>(self) -> Result<(&'input [u8; N], Self), consume::Error> {
        let (head, plan) = self.input.0.try_split()?;
        Ok((
            head,
            Self {
                input: (plan, self.input.1),
            },
        ))
    }
}