pub struct RouteNonMatch { /* private fields */ }
Expand description
The error type used for a non-matching route, as returned by RouteMatcher::is_match
. Multiple
values of this type can be combined by matchers that are wrapping other matchers, using the
intersection
/ union
methods. The data within is used by the Router
to create a
Response
when no routes were successfully matched.
#[derive(Clone)]
struct MyRouteMatcher;
impl RouteMatcher for MyRouteMatcher {
fn is_match(&self, state: &State) -> Result<(), RouteNonMatch> {
match state.borrow::<Method>() {
&Method::GET => Ok(()),
_ => Err(
RouteNonMatch::new(StatusCode::METHOD_NOT_ALLOWED)
.with_allow_list(&[Method::GET]),
),
}
}
}
Implementations
sourceimpl RouteNonMatch
impl RouteNonMatch
sourcepub fn new(status: StatusCode) -> RouteNonMatch
pub fn new(status: StatusCode) -> RouteNonMatch
Creates a new RouteNonMatch
value with the given HTTP status.
sourcepub fn with_allow_list(self, allow: &[Method]) -> RouteNonMatch
pub fn with_allow_list(self, allow: &[Method]) -> RouteNonMatch
Adds an allow list to a RouteNonMatch
. Typically this is used with a 405 Method Not Allowed
status code, so the Router
can accurately populate the Allow
header in the
response. It must be populated by any RouteMatcher
which restricts the HTTP method.
sourcepub fn intersection(self, other: RouteNonMatch) -> RouteNonMatch
pub fn intersection(self, other: RouteNonMatch) -> RouteNonMatch
Takes the intersection of two RouteNonMatch
values, producing a single result. This is
intended for use in cases where two RouteMatcher
instances with a logical AND
connection have both indicated a non-match, and their results need to be aggregated.
This is typically for Gotham internal use, but may be useful for implementors of matchers
which wrap other RouteMatcher
instances. See the AndRouteMatcher
implementation (in
gotham::router::route::matcher::and
) for an example.
sourcepub fn union(self, other: RouteNonMatch) -> RouteNonMatch
pub fn union(self, other: RouteNonMatch) -> RouteNonMatch
Takes the union of two RouteNonMatch
values, producing a single result. This is intended
for use in cases where two RouteMatcher
instances with a logical OR connection have
both indicated a non-match, and their results need to be aggregated.
This is typically for Gotham internal use, but may be useful for implementors of matchers
which wrap other RouteMatcher
instances. See the Node::select_route
implementation (in
gotham::router::tree
) for an example.
Trait Implementations
sourceimpl Clone for RouteNonMatch
impl Clone for RouteNonMatch
sourcefn clone(&self) -> RouteNonMatch
fn clone(&self) -> RouteNonMatch
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl From<RouteNonMatch> for StatusCode
impl From<RouteNonMatch> for StatusCode
sourcefn from(val: RouteNonMatch) -> StatusCode
fn from(val: RouteNonMatch) -> StatusCode
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for RouteNonMatch
impl Send for RouteNonMatch
impl Sync for RouteNonMatch
impl Unpin for RouteNonMatch
impl UnwindSafe for RouteNonMatch
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more