[][src]Struct cord_client::Conn

pub struct Conn { /* fields omitted */ }

A Conn is used to connect to and communicate with a broker.

Examples

use cord_client::Conn;
use futures::{future, Future};
use tokio;

let fut = Conn::new("127.0.0.1:7101".parse().unwrap()).and_then(|mut conn| {
    // Tell the broker we're going to provide the namespace /users
    conn.provide("/users".into()).unwrap();

    // Start publishing events...
    conn.event("/users/mark".into(), "Mark has joined").unwrap();

    Ok(())
}).map_err(|_| ());

tokio::run(fut);

Methods

impl Conn[src]

pub fn new(addr: SocketAddr) -> impl Future<Item = Conn, Error = Error>[src]

Connect to a broker

pub fn forward<S>(self, stream: S) -> impl Future<Item = Self, Error = Error> where
    S: Stream<Item = Message, Error = Error>, 
[src]

If you have a stream that produces Messages, you can forward that directly to the inner Sink instead of calling the helper methods.

pub fn provide(&mut self, namespace: Pattern) -> Result<()>[src]

Inform the broker that you will be providing a new namespace

pub fn revoke(&mut self, namespace: Pattern) -> Result<()>[src]

Inform the broker that you will no longer be providing a namespace

pub fn subscribe(&mut self, namespace: Pattern) -> Result<Subscriber>[src]

Subscribe to another provider's namespace

Examples


conn.subscribe("/users/".into()).unwrap().for_each(|msg| {
    // Handle the message...
    dbg!("The following user just joined: {}", msg);

    Ok(())
})

pub fn unsubscribe(&mut self, namespace: Pattern) -> Result<()>[src]

Unsubscribe from another provider's namespace

pub fn event<S: Into<String>>(
    &mut self,
    namespace: Pattern,
    data: S
) -> Result<()>
[src]

Publish an event to your subscribers

Trait Implementations

impl Clone for Conn[src]

Auto Trait Implementations

impl !RefUnwindSafe for Conn

impl Send for Conn

impl Sync for Conn

impl Unpin for Conn

impl !UnwindSafe for Conn

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.