Enum EventSender

Source
pub enum EventSender {
    Unbounded(UnboundedSender<Msg>),
    Bounded(Sender<Msg>),
}
Expand description

Event sender abstraction that can be either bounded or unbounded.

EventSender provides a unified interface for sending messages through either bounded or unbounded channels. This abstraction allows the framework to switch between different channel types without changing the API.

§Examples

use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;

// Create from unbounded channel
let (tx, _rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);

// Send a message
let msg: Msg = Box::new("Hello");
sender.send(msg).unwrap();

Variants§

§

Unbounded(UnboundedSender<Msg>)

Unbounded channel sender used for unlimited-capacity message delivery.

§

Bounded(Sender<Msg>)

Bounded channel sender that applies backpressure when full.

Implementations§

Source§

impl EventSender

Source

pub fn send(&self, msg: Msg) -> Result<(), Error>

Send a message through the channel.

Attempts to send a message through the underlying channel. For unbounded channels, this will only fail if the receiver has been dropped. For bounded channels, this may also fail due to backpressure (channel full).

§Arguments
  • msg - The message to send
§Returns

Returns Ok(()) if the message was sent successfully, or an error if:

  • The channel is closed (Error::ChannelClosed)
  • The channel is full (Error::ChannelFull) for bounded channels
§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;

let (tx, _rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);

let msg: Msg = Box::new(42);
match sender.send(msg) {
    Ok(()) => println!("Message sent!"),
    Err(e) => eprintln!("Failed to send: {}", e),
}
Source

pub fn is_closed(&self) -> bool

Check if the sender is closed.

Returns true if the receiver side of the channel has been dropped, meaning that any future send operations will fail.

§Returns

true if the channel is closed, false otherwise

§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;

let (tx, rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);

assert!(!sender.is_closed());
drop(rx); // Drop the receiver
assert!(sender.is_closed());
Source

pub fn from_unbounded(tx: UnboundedSender<Msg>) -> Self

Create an EventSender from an UnboundedSender (for backward compatibility).

This method creates an EventSender wrapping an unbounded channel sender. Unbounded channels have unlimited capacity and never apply backpressure.

§Arguments
  • tx - The unbounded sender to wrap
§Returns

An EventSender that uses the provided unbounded channel

§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;

let (tx, _rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);
Source

pub fn from_bounded(tx: Sender<Msg>) -> Self

Create an EventSender from a bounded Sender (for testing).

This method creates an EventSender wrapping a bounded channel sender. Bounded channels have limited capacity and will apply backpressure when full. This is primarily used in testing scenarios to verify behavior under backpressure conditions.

§Arguments
  • tx - The bounded sender to wrap
§Returns

An EventSender that uses the provided bounded channel

§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;

let (tx, _rx) = mpsc::channel::<Msg>(10); // Capacity of 10
let sender = EventSender::from_bounded(tx);

Trait Implementations§

Source§

impl Clone for EventSender

Source§

fn clone(&self) -> EventSender

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<Sender<Box<dyn Any + Send>>> for EventSender

Source§

fn from(tx: Sender<Msg>) -> Self

Converts to this type from the input type.
Source§

impl From<UnboundedSender<Box<dyn Any + Send>>> for EventSender

Source§

fn from(tx: UnboundedSender<Msg>) -> Self

Converts to this type from the input type.

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.