use core::{marker::PhantomData, mem::MaybeUninit};
usecrate::weak_slice::WeakSliceMut;
pubstruct Pending<'a> { /// start of the allocation
buf: WeakSliceMut<'a, MaybeUninit<u8>>, /// next pending byte to output to the stream
out: usize, /// number of bytes in the pending buffer pub(crate) pending: usize, /// semantically we're storing a mutable slice of bytes
_marker: PhantomData<&'a mut [u8]>,
}
impl<'a> Pending<'a> { pubfn reset_keep(&mutself) { // keep the buffer as it is self.pending = 0;
}
pubfn pending(&self) -> &[u8] { let slice = &self.buf.as_slice()[self.out..][..self.pending]; // SAFETY: the slice contains initialized bytes. unsafe { &*(slice as *const [MaybeUninit<u8>] as *const [u8]) }
}
/// Number of bytes that can be added to the pending buffer until it is full pub(crate) fn remaining(&self) -> usize { self.buf.len() - (self.out + self.pending)
}
/// Total number of bytes that can be stored in the pending buffer pub(crate) fn capacity(&self) -> usize { self.buf.len()
}
#[inline(always)] #[track_caller] /// Mark a number of pending bytes as no longer pending pubfn advance(&mutself, number_of_bytes: usize) {
debug_assert!(self.pending >= number_of_bytes);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.