Struct srve::Server[][src]

pub struct Server<S, M> { /* fields omitted */ }

Represents our server.

Implementations

impl<S, M> Server<S, M> where
    S: Default,
    M: Serialize + DeserializeOwned
[src]

pub fn bind(addr: &str) -> Result<Self, Box<dyn Error>>[src]

Create a new server by binding to a listening TCP port.

pub fn on_closed(self, cb: fn(_: &mut Conn<S, M>)) -> Self[src]

Setup a callback for closed connections.

This callback will only ever be run, when the client terminates the connection to the server.

pub fn on_closed_unexpected(self, cb: fn(_: &mut Conn<S, M>)) -> Self[src]

Setup a callback for unexpectedly closed connections.

This callback will be run when the connection is closed by the client when the server is receiving a message.

pub fn on_connection(self, cb: fn(_: &mut Conn<S, M>)) -> Self[src]

Setup a callback for each new connection.

This callback will be run when the server stablishes a new connection with a client, before any messages are recevied.

pub fn on_error(self, cb: fn(_: &mut Conn<S, M>, _: Box<dyn Error>)) -> Self[src]

Setup a callback for connection errors.

This callback will be run whenever there is an error attempting to get the next message from a connection, e.g. a bad message that fails to be deserialized.

pub fn on_message(self, cb: fn(_: &mut Conn<S, M>, _: M)) -> Self[src]

Setup a calback for each received message.

This is the main callbcak, which is run every time a connection sends a new message.

pub fn run(self) -> ![src]

Run the server by using the given callback function on connections.

At this moment, the server starts adding inbound connections and handling them, by using the callbacks given during its creation.

Auto Trait Implementations

impl<S, M> !RefUnwindSafe for Server<S, M>

impl<S, M> Send for Server<S, M> where
    M: Send,
    S: Send

impl<S, M> !Sync for Server<S, M>

impl<S, M> Unpin for Server<S, M> where
    M: Unpin

impl<S, M> !UnwindSafe for Server<S, M>

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, 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.