Skip to main content

ReceiverBuilder

Struct ReceiverBuilder 

Source
pub struct ReceiverBuilder<R>
where R: AsyncReadExt + Send + Sync + Unpin + 'static,
{ /* private fields */ }
Expand description

Builder for configuring and creating a Receiver and ReceiverTask.

This builder allows you to customize the reception pipeline parameters before spawning the background task that handles network I/O and message reassembly.

§Parameters

  • capacity: Maximum number of messages that can be buffered per priority level (default: 16)
  • max_frag_size: Maximum size of a message fragment in bytes (default: 1GiB)

Implementations§

Source§

impl<R> ReceiverBuilder<R>
where R: AsyncReadExt + Send + Sync + Unpin + 'static,

Source

pub fn capacity(self, capacity: usize) -> Self

Sets the maximum number of messages that can be buffered per priority level.

Default: 16 messages per priority level

Higher values allow for more buffering during traffic bursts but consume more memory. Lower values reduce memory usage but may cause messages to be dropped under congestion.

Source

pub fn timeout(self, timeout: Duration) -> Self

Sets the timeout for waiting for messages during receive operations.

This timeout determines how long Receiver::recv() will wait for a message to arrive before returning RecvError::Timeout. The timeout applies to each individual receive call.

This is the initial timeout value used when the receiver is built. It can be changed later using Receiver::timeout().

Default: 10 seconds

§Examples
// Configure a 30-second timeout during construction
let (receiver, task) = thubo::receiver(reader).timeout(Duration::from_secs(30)).build();
Source

pub fn max_frag_size(self, max_frag_size: usize) -> Self

Sets the maximum size of a message fragment in bytes.

Default: 65536 bytes (64KB)

This should match the max_frag_size configured on the sender side. Messages larger than this size will be automatically fragmented by the sender and reassembled by the receiver. Smaller values reduce latency for small messages but increase overhead for large messages.

Source

pub fn build(self) -> (Receiver, ReceiverTask<R>)

Builds and returns a Receiver and ReceiverTask.

This method creates the complete reception pipeline:

  • Receiver: Handle for receiving messages in strict priority order
  • ReceiverTask: Background task that manages network I/O, defragmentation, and message routing
§Background Task

The returned ReceiverTask runs until:

  • The connection is closed (EOF or network error)
  • A read timeout occurs
  • The task is explicitly stopped via ReceiverTask::stop()

Auto Trait Implementations§

§

impl<R> Freeze for ReceiverBuilder<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for ReceiverBuilder<R>
where R: RefUnwindSafe,

§

impl<R> Send for ReceiverBuilder<R>

§

impl<R> Sync for ReceiverBuilder<R>

§

impl<R> Unpin for ReceiverBuilder<R>

§

impl<R> UnsafeUnpin for ReceiverBuilder<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for ReceiverBuilder<R>
where R: UnwindSafe,

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.