[][src]Struct twitchchat::Client

pub struct Client { /* fields omitted */ }

Client allows for reading and writing.

It reads from an tokio::io::AsyncRead and allows subscription to events via a Dispatcher.

It allows encoding of messages to a tokio::io::AsyncWrite

Event subcription returns a Stream of Messages for that event.

The client allows you to get a Writer which lets you send messages to the connection.

Using the client

You drive a Client to completion with an AsyncRead and AsyncWrite pair by calling run.

run will read from the connection end an error or EOF is received, dispatching messages to any event subscribers.

The Writer uses the AsyncWrite part to encode messages to it.

Example

This example is not tested
// make a client
let mut client = Client::new();
// get a cloneable writer
let mut writer = client.writer()
// subscribe to the join events (multiple subscriptions to the same event is allowed)
let mut join_stream = client.dispatcher().await.subscribe::<event::Join>();
tokio::task::spawn(async move {
    // will read until the client drops, or the event subscription is cleared
    while let Some(join_msg) = join_stream.next().await {
        // join_msg is a twitchchat::messages::JoinMessage
    }
});

// wait for the client to read to the end, driving any subscriptions
client.run(read_impl, write_impl).await;

Methods

impl Client[src]

pub fn new() -> Self[src]

Create a new client

pub async fn dispatcher<'_, '_>(&'_ self) -> MutexGuard<'_, Dispatcher>[src]

Get the dispatcher

pub fn writer(&self) -> Writer[src]

Get a new writer

pub async fn stop<'_>(&'_ self) -> Result<(), Error>[src]

Stops the running task

run will return Ok(Status::Canceled)

pub async fn run<'_, R, W>(&'_ self, read: R, write: W) -> Result<Status, Error> where
    R: AsyncRead + Send + Sync + Unpin + 'static,
    W: AsyncWrite + Send + Sync + Unpin + 'static, 
[src]

Run the client to completion, dispatching messages to the subscribers

Returns

Trait Implementations

impl Clone for Client[src]

impl Debug for Client[src]

impl Default for Client[src]

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.