Skip to main content

ChunkedBuffer

Struct ChunkedBuffer 

Source
pub struct ChunkedBuffer { /* private fields */ }
Expand description

A buffer that manages chunked data.

Implementations§

Source§

impl ChunkedBuffer

Source

pub fn new(chunk_size: usize, max_size: usize) -> Self

Create a new chunked buffer.

Source

pub fn with_defaults() -> Self

Create a new chunked buffer with default settings.

Source

pub fn calculate_chunks(&self, total_size: u64) -> usize

Calculate the number of chunks needed for a given size.

Source

pub fn descriptor_for_index( &self, index: usize, total_size: u64, ) -> ChunkDescriptor

Get a chunk descriptor for a given index.

Source

pub async fn push(&self, descriptor: ChunkDescriptor, data: Bytes) -> Result<()>

Push a chunk into the buffer.

Source

pub async fn pop(&self) -> Result<Option<(ChunkDescriptor, Bytes)>>

Pop a chunk from the buffer.

Source

pub async fn peek(&self) -> Result<Option<ChunkDescriptor>>

Peek at the next chunk without removing it.

Source

pub async fn len(&self) -> usize

Get the number of chunks currently in the buffer.

Source

pub async fn is_empty(&self) -> bool

Check if the buffer is empty.

Source

pub async fn rebase_if_empty(&self, index: usize) -> bool

Move the write cursor to index, but only while the buffer is drained.

Self::push enforces a strictly sequential producer: a chunk is only accepted when its index equals the internal write cursor. A pull-based consumer such as crate::io::ChunkedReader serves a buffer miss with a direct read that deliberately bypasses this buffer, which leaves the write cursor lagging behind the stream and makes every later read-ahead push fail with StreamingError::InvalidOperation. Re-basing while the buffer holds nothing lets read-ahead resume at the consumer’s real position without weakening the ordering check for buffered chunks.

Returns true when the cursor was moved, false when the buffer still holds chunks (in which case re-basing would reorder them and is refused).

Source

pub async fn size_bytes(&self) -> usize

Get the current buffer size in bytes.

Source

pub async fn is_complete(&self) -> bool

Check if writing is complete.

Source

pub async fn clear(&self)

Clear all chunks from the buffer.

Source

pub async fn stats(&self) -> BufferStats

Get buffer statistics.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more