Struct Server

Source
pub struct Server<S, M> { /* private fields */ }
Expand description

Represents our server.

Implementations§

Source§

impl<S, M> Server<S, M>

Source

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

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

Source

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

Setup a callback for closed connections.

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

Source

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

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.

Source

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

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.

Source

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

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.

Source

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

Setup a calback for each received message.

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

Source

pub fn run(self) -> !

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> Freeze for Server<S, M>

§

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>
where M: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.