Skip to main content

MultipartPush

Struct MultipartPush 

Source
pub struct MultipartPush<'a, const N: usize> { /* private fields */ }
Expand description

Guard returned by BytearrayRingbuffer::push_multipart and BytearrayRingbuffer::push_multipart_force.

Accumulates payload bytes written via repeated Self::push calls. When dropped, the completed packet (header + payload + footer) is committed to the ring buffer. Call Self::cancel to discard the in-progress write without committing a packet.

In force mode any existing packets that were displaced to make room are permanently lost, even if the write is cancelled.

Implementations§

Source§

impl<'a, const N: usize> MultipartPush<'a, N>

Source

pub fn push(&mut self, data: &[u8]) -> Result<(), NotEnoughSpaceError>

Appends data to the packet currently being written.

May be called multiple times. The chunks are concatenated in order.

In normal mode returns NotEnoughSpaceError when there is not enough space in the buffer to fit data plus the 4-byte footer. In force mode it drops the oldest packets until there is room.

§Errors

Returns NotEnoughSpaceError if:

  • The total accumulated payload would exceed N - 8 (the maximum for any single packet).
  • In normal mode: there is not enough unused space.
  • In force mode: even after dropping all existing packets there is still not enough space (meaning the total accumulated payload exceeds what can fit in the buffer).
Source

pub fn cancel(self)

Discards the in-progress packet without committing it to the ring buffer.

Rewinds head to the position it had before BytearrayRingbuffer::push_multipart was called. Any packets that were already dropped in force mode are permanently lost.

Trait Implementations§

Source§

impl<'a, const N: usize> Drop for MultipartPush<'a, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for MultipartPush<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for MultipartPush<'a, N>

§

impl<'a, const N: usize> Send for MultipartPush<'a, N>

§

impl<'a, const N: usize> Sync for MultipartPush<'a, N>

§

impl<'a, const N: usize> Unpin for MultipartPush<'a, N>

§

impl<'a, const N: usize> UnsafeUnpin for MultipartPush<'a, N>

§

impl<'a, const N: usize> !UnwindSafe for MultipartPush<'a, N>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.