[][src]Struct showdown::Sender

pub struct Sender { /* fields omitted */ }

Message sender.

Methods

impl Sender[src]

pub fn send_global_command(
    &mut self,
    command: &str
) -> impl Future<Item = (), Error = Error> + '_
[src]

Sends a global command.

Example

#![feature(async_await, await_macro, futures_api)]
#![recursion_limit = "128"]

use futures03::prelude::*;
use showdown::message::{Kind, ParsedMessage, QueryResponse};
use showdown::{connect, Result, RoomId};
use tokio::await;
use tokio::runtime::Runtime;

async fn start() -> Result<()> {
    let (mut sender, mut receiver) = await!(connect("showdown"))?;
    await!(sender.send_global_command("cmd rooms"))?;
    loop {
        let received = await!(receiver.receive())?;
        if let Kind::QueryResponse(QueryResponse::Rooms(rooms)) = received.parse().kind {
            assert!(rooms
                .official
                .iter()
                .any(|room| room.title == "Tournaments"));
            return Ok(());
        }
    }
}

Runtime::new()
    .unwrap()
    .block_on_all(start().boxed().compat())
    .unwrap();

pub fn send_chat_message(
    &mut self,
    room_id: RoomId,
    message: &str
) -> impl Future<Item = (), Error = Error> + '_
[src]

Sends a message in a chat room.

Examples

#![feature(async_await, await_macro, futures_api)]
#![recursion_limit = "128"]

use futures03::prelude::*;
use showdown::message::{Kind, ParsedMessage, QueryResponse};
use showdown::{connect, Result, RoomId};
use tokio::await;
use tokio::runtime::Runtime;

async fn start() -> Result<()> {
    let (mut sender, mut receiver) = await!(connect("showdown"))?;
    await!(sender.send_global_command("join lobby"))?;
    await!(sender.send_chat_message(RoomId::LOBBY, "/roomdesc"));
    loop {
        if let Kind::Html(html) = await!(receiver.receive())?.parse().kind {
            assert!(html.contains("Relax here amidst the chaos."));
            return Ok(());
        }
    }
}

Runtime::new()
    .unwrap()
    .block_on_all(start().boxed().compat())
    .unwrap();

Trait Implementations

impl Debug for Sender[src]

Auto Trait Implementations

impl Send for Sender

impl Sync for Sender

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

impl<T> Erased for T

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.