Skip to main content

ServeMux

Struct ServeMux 

Source
pub struct ServeMux { /* private fields */ }
Expand description

HTTP request multiplexer. Port of Go’s http.ServeMux.

Matching rules (same as Go):

  1. Exact match wins over prefix match.
  2. Among prefix matches, the longest pattern wins.
  3. Patterns ending with / are subtree patterns (prefix match).
  4. Patterns not ending with / are exact match only.

Implementations§

Source§

impl ServeMux

Source

pub fn new() -> Self

Source

pub fn handle(&self, pattern: &str, handler: impl Handler + 'static)

Register a handler for the given pattern.

Source

pub fn handle_func<F>(&self, pattern: &str, f: F)
where F: Fn(&mut dyn ResponseWriter, &Request) + Send + Sync + 'static,

Register a function as a handler.

Source

pub fn match_handler(&self, path: &str) -> Option<Arc<dyn Handler>>

Find the best matching handler for path.

Trait Implementations§

Source§

impl Default for ServeMux

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Handler for ServeMux

Source§

fn serve_http(&self, w: &mut dyn ResponseWriter, r: &Request)

Auto Trait Implementations§

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.