[−][src]Struct twitchchat::Client
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
// 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]
R: AsyncRead + Send + Sync + Unpin + 'static,
W: AsyncWrite + Send + Sync + Unpin + 'static,
Run the client to completion, dispatching messages to the subscribers
Returns
- An error if one was encountered while in operation
Ok(Status::Eof)
if it ran to completionOk(Status::Canceled)
ifstop
was called
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,