[][src]Struct httpbis::ServerHandlerPaths

pub struct ServerHandlerPaths { /* fields omitted */ }

Convient implementation of ServerHandler which allows delegation to multiple ServerHandler implementations provided by user.

Implementations

impl ServerHandlerPaths[src]

pub fn new() -> ServerHandlerPaths[src]

Create a new Service implementation which returns 404 on all requests by default.

pub fn set_service(&mut self, path: &str, service: Arc<dyn ServerHandler>)[src]

Register a service for given path.


struct Root {}
struct Files {}

impl ServerHandler for Root {
    fn start_request(&self, _context: ServerHandlerContext, _req: ServerRequest, mut resp: ServerResponse) -> httpbis::Result<()> {
        resp.send_found_200_plain_text("This is root page")?;
        Ok(())
    }
}

impl ServerHandler for Files {
    fn start_request(&self, _context: ServerHandlerContext, _req: ServerRequest, mut resp: ServerResponse) -> httpbis::Result<()> {
        resp.send_found_200_plain_text("This is files")?;
        Ok(())
    }
}

let mut server = ServerBuilder::new_plain();
server.service.set_service("/", Arc::new(Root{}));
server.service.set_service("/files", Arc::new(Files{}));

pub fn set_service_fn<F>(&mut self, path: &str, service: F) where
    F: Fn(ServerHandlerContext, ServerRequest, ServerResponse) -> Result<()> + Send + Sync + 'static, 
[src]

pub fn remove_service(&mut self, path: &str) -> Option<Arc<dyn ServerHandler>>[src]

Trait Implementations

impl Default for ServerHandlerPaths[src]

impl ServerHandler for ServerHandlerPaths[src]

Auto Trait Implementations

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.