Struct paperplane::Server[][src]

pub struct Server<Session> { /* fields omitted */ }

A TCP WebSocket Server.

Implementations

impl<Session> Server<Session> where
    Session: Default + Clone + Send + Sync + 'static, 
[src]

pub fn new(cap: usize) -> Arc<Self>[src]

Create a new Server instance. Takes a capacity for channel and returns Arc<Server> for convenience.

pub async fn accept(self: &Arc<Self>, stream: TcpStream) -> Result<u128>[src]

Accept given TcpStream as a WebSocket connection.

pub async fn listen<A>(self: &Arc<Self>, addr: A) -> Result<()> where
    A: ToSocketAddrs
[src]

Start listening on given socket address.

pub async fn close(self: &Arc<Self>) -> Result<()>[src]

Close all connections and stop all listeners.

pub async fn next(&self) -> Option<Event>[src]

Get next server event.

pub async fn send(&self, id: u128, msg: Message) -> Result<()>[src]

Send a message to a connection with the given id.

pub async fn send_all(&self, msg: Message) -> Result<()>[src]

Send a message to all current connections.

pub async fn send_map<F>(&self, map: F) -> Result<()> where
    F: Fn(u128) -> Option<Message>, 
[src]

Loop through connections and send messages determined by the given closure.

pub async fn kick(&self, id: u128, reason: &str) -> Result<()>[src]

Close a connection with the given id and reason.

pub async fn kick_all(self: &Arc<Self>, reason: &str) -> Result<()>[src]

Close all current connections with the given reason.

pub async fn kick_map<F>(self: &Arc<Self>, map: F) -> Result<()> where
    F: Fn(u128) -> Option<String>, 
[src]

Loop through connections and kick the ones for which's id the given closure returns a reason.

pub async fn get_session(&self, id: u128) -> Option<Session>[src]

Get session by connection id.

pub async fn set_session(&self, id: u128, state: Session) -> Result<Session>[src]

Set session by connection id and return the previous session.

pub async fn update_session<F>(&self, id: u128, predicate: F) -> Result<()> where
    F: FnMut(&Session) -> Session, 
[src]

Replace session for connection id using the given predicate.

pub async fn find_session<F>(&self, predicate: F) -> Option<(u128, Session)> where
    F: Fn(&Session) -> bool
[src]

Find the first connection id and session pair that matches the given predicate.

pub async fn find_and_update_session<F>(&self, predicate: F) -> Result<()> where
    F: FnMut(u128, &Session) -> Option<Session>, 
[src]

Update the first pair that the given predicate returns some for.

pub async fn filter_sessions<F>(&self, predicate: F) -> Vec<(u128, Session)> where
    F: Fn(&Session) -> bool
[src]

Get a list of connection id and session pairs that match the given predicate.

pub async fn filter_and_update_sessions<F>(&self, predicate: F) -> usize where
    F: FnMut(u128, &Session) -> Option<Session>, 
[src]

Filter and update pairs that the given predicate returns some for.

Auto Trait Implementations

impl<Session> !RefUnwindSafe for Server<Session>[src]

impl<Session> Send for Server<Session> where
    Session: Send
[src]

impl<Session> Sync for Server<Session> where
    Session: Send + Sync
[src]

impl<Session> Unpin for Server<Session> where
    Session: Unpin
[src]

impl<Session> !UnwindSafe for Server<Session>[src]

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> Same<T> for T

type Output = T

Should always be Self

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,