Struct Server

Source
pub struct Server {
    pub hostname: String,
    pub port: u16,
    /* private fields */
}
Expand description

The “heart” of the module; the server struct

It does everything: process requests, pass them to handlers, reject them if they are malformed

Fields§

§hostname: String

The hostname the server is listening to for requests

§port: u16

The port the server is listening for requests

Implementations§

Source§

impl Server

Source

pub fn new<S, N>(hostname: S, port: N) -> Self
where S: Into<String>, N: Into<u16>,

Initialize a Server by passing a hostname and a port number

Source

pub fn start(&self, callback: fn())

Start the server and make it process incoming connections

Source

pub fn on<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Append a function handler that will be called on any request in a specific path

Source

pub fn on_get<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Same as the on() function, but processes only GET requests

Source

pub fn on_head<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Same as the on() function, but processes only HEAD requests

Source

pub fn on_post<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Same as the on() function, but processes only POST requests

Source

pub fn on_put<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Same as the on() function, but processes only PUT requests

Source

pub fn on_delete<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Same as the on() function, but processes only DELETE requests

Source

pub fn on_directory<S, H>(&mut self, path: S, handler: H)
where S: Into<String>, H: Fn(Request, Response<'_>) + 'static,

Append a directory handler that will be called on any request in a specific path

Auto Trait Implementations§

§

impl Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl !Send for Server

§

impl !Sync for Server

§

impl Unpin for Server

§

impl !UnwindSafe for Server

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.