[][src]Struct gotham::router::route::matcher::and::AndRouteMatcher

pub struct AndRouteMatcher<T, U> where
    T: RouteMatcher,
    U: RouteMatcher
{ /* fields omitted */ }

Allows multiple RouteMatcher values to be combined when accessing a request.

Examples

                                         AndRouteMatcher, AcceptHeaderRouteMatcher};
  let methods = vec![Method::GET, Method::HEAD];
  let supported_media_types = vec![mime::APPLICATION_JSON];
  let method_matcher = MethodOnlyRouteMatcher::new(methods);
  let accept_matcher = AcceptHeaderRouteMatcher::new(supported_media_types);
  let matcher = AndRouteMatcher::new(method_matcher, accept_matcher);

  state.put(Method::GET);

  // Request that matches both requirements
  let mut headers = HeaderMap::new();
  headers.insert(ACCEPT, mime::APPLICATION_JSON.to_string().parse().unwrap());
  state.put(headers);
  assert!(matcher.is_match(&state).is_ok());

  // Request that fails method requirements
  state.put(Method::POST);
  assert!(matcher.is_match(&state).is_err());

  // Request that fails accept header
  state.put(Method::GET);
  let mut headers = HeaderMap::new();
  headers.insert(ACCEPT, mime::TEXT.to_string().parse().unwrap());
  state.put(headers);
  assert!(matcher.is_match(&state).is_err());

Implementations

impl<T, U> AndRouteMatcher<T, U> where
    T: RouteMatcher,
    U: RouteMatcher
[src]

pub fn new(t: T, u: U) -> Self[src]

Creates a new AndRouteMatcher

Trait Implementations

impl<T: Clone, U: Clone> Clone for AndRouteMatcher<T, U> where
    T: RouteMatcher,
    U: RouteMatcher
[src]

impl<T, U> RouteMatcher for AndRouteMatcher<T, U> where
    T: RouteMatcher,
    U: RouteMatcher
[src]

Auto Trait Implementations

impl<T, U> RefUnwindSafe for AndRouteMatcher<T, U>

impl<T, U> Send for AndRouteMatcher<T, U> where
    T: Send,
    U: Send

impl<T, U> Sync for AndRouteMatcher<T, U> where
    T: Sync,
    U: Sync

impl<T, U> Unpin for AndRouteMatcher<T, U> where
    T: Unpin,
    U: Unpin

impl<T, U> UnwindSafe for AndRouteMatcher<T, U> where
    T: UnwindSafe,
    U: UnwindSafe

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<M> IntoRouteMatcher for M where
    M: RouteMatcher + Send + Sync + 'static, 
[src]

type Output = M

The concrete RouteMatcher each implementation will provide.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,