pub struct Builder { /* private fields */ }Expand description
Builder for a weighted channel. Use channel for the common case.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(buffer: usize, max_weight: usize) -> Self
pub fn new(buffer: usize, max_weight: usize) -> Self
Create a builder with the two required bounds:
buffer: the message-count buffer of the underlying tokio channel. It is the backstop for zero- or near-zero-weight messages, which the weight budget alone would not bound. Must be> 0.max_weight: the total weight allowed in the channel at once. Must be in1..=u32::MAX(about 4 GiB).
Defaults: Oversized::Allow, min_weight of 1, and no observer.
Sourcepub fn min_weight(self, min_weight: usize) -> Self
pub fn min_weight(self, min_weight: usize) -> Self
Minimum weight counted for any message. A message lighter than this still
takes this much budget, so a flood of tiny messages cannot fill the channel
without the budget noticing. Defaults to 1; set it to 0 to let zero-weight
messages through without taking any budget (then only buffer bounds them).
Sourcepub fn oversized(self, policy: Oversized) -> Self
pub fn oversized(self, policy: Oversized) -> Self
How to handle a message that weighs more than the whole budget. See
Oversized.
Sourcepub fn on_oversized<F>(self, hook: F) -> Self
pub fn on_oversized<F>(self, hook: F) -> Self
Register an observer called as (message_weight, max_weight) whenever a
message weighs more than the budget, whatever the Oversized choice.
Sourcepub fn build<T>(self) -> (WeightedSender<T>, WeightedReceiver<T>)
pub fn build<T>(self) -> (WeightedSender<T>, WeightedReceiver<T>)
Build the sender/receiver pair.
§Panics
Panics if buffer is 0, or if max_weight is 0 or greater than u32::MAX.