Struct paperplane::Server [−][src]
A TCP WebSocket Server.
Implementations
impl<Session> Server<Session> where
Session: Default + Clone + Send + Sync + 'static,
[src]
Session: Default + Clone + Send + Sync + 'static,
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]
A: ToSocketAddrs,
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]
F: Fn(u128) -> Option<Message>,
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]
F: Fn(u128) -> Option<String>,
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]
F: FnMut(&Session) -> Session,
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]
F: Fn(&Session) -> bool,
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]
F: FnMut(u128, &Session) -> Option<Session>,
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]
F: Fn(&Session) -> bool,
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]
F: FnMut(u128, &Session) -> Option<Session>,
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]
Session: Send,
impl<Session> Sync for Server<Session> where
Session: Send + Sync,
[src]
Session: Send + Sync,
impl<Session> Unpin for Server<Session> where
Session: Unpin,
[src]
Session: Unpin,
impl<Session> !UnwindSafe for Server<Session>
[src]
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,
pub 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> Same<T> for T
type Output = T
Should always be Self
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.
pub 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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,