Skip to main content

GenericBufferedSender

Struct GenericBufferedSender 

Source
pub struct GenericBufferedSender<T, U>
where T: Serialize,
{ sender: GenericSender<T>, buffer: RefCell<Vec<U>>, buffering: Box<dyn Fn(Vec<U>) -> T>, max_buffer: usize, }
Expand description

A buffered sender that collects individual messages (U) and sends them as a single batched message (T) via a user-provided packing closure.

The buffer is flushed automatically when it reaches max_buffer items, or explicitly via flush. send_immediate combines the current buffer contents with the new message into a single packed message, ensuring ordering without an extra flush step.

Fields§

§sender: GenericSender<T>§buffer: RefCell<Vec<U>>§buffering: Box<dyn Fn(Vec<U>) -> T>§max_buffer: usize

Implementations§

Source§

impl<T: Serialize, U> GenericBufferedSender<T, U>

Source

pub fn new( sender: GenericSender<T>, buffering: Box<dyn Fn(Vec<U>) -> T>, max_buffer: usize, ) -> Self

Create a new buffered sender.

  • sender — the underlying GenericSender<T> that delivers packed messages.
  • buffering — closure that packs a Vec<U> into a single T.
  • max_buffer — automatic flush is triggered when the buffer reaches this size.
Source

pub fn is_empty(&self) -> bool

Returns true if the buffer contains no pending messages.

Source

pub fn len(&self) -> usize

Returns the number of pending messages in the buffer.

Source

pub fn set_max_buffer(&mut self, max: usize)

Change the auto-flush threshold.

Source

pub fn send(&self, msg: U) -> SendResult

Buffer a message for later batched delivery.

If the buffer reaches max_buffer items an automatic flush is triggered.

Source

pub fn send_immediate(&self, msg: U) -> SendResult

Deliver a message immediately, combining it with any buffered messages into a single packed T.

Source

pub fn flush(&self) -> SendResult

Flush all buffered messages by packing them into a single T and sending it.

Trait Implementations§

Source§

impl<T: Serialize, U> Drop for GenericBufferedSender<T, U>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, U> !Freeze for GenericBufferedSender<T, U>

§

impl<T, U> !RefUnwindSafe for GenericBufferedSender<T, U>

§

impl<T, U> !Send for GenericBufferedSender<T, U>

§

impl<T, U> !Sync for GenericBufferedSender<T, U>

§

impl<T, U> Unpin for GenericBufferedSender<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnsafeUnpin for GenericBufferedSender<T, U>

§

impl<T, U> !UnwindSafe for GenericBufferedSender<T, U>

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
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> Same for T

Source§

type Output = T

Should always be Self
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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T