pub struct Bound<M: Model>(pub M);Expand description
A model resolved from a route parameter.
Looks the row up by the model’s
route key — the primary key
unless the model says otherwise, which is how /posts/{post} binds by slug
while /users/{user} binds by id.
§Which parameter
The one named after the model, lower-cased: Post reads {post}. Laravel’s
convention, and it is worth keeping to — a route whose parameter is named
something else should say so with BoundAs, not leave the reader
guessing which of two parameters was meant.
§Failures
- no such parameter on the route → a
500, because that is a wiring mistake rather than anything the caller did; - no such row → a
404naming the model, exactly asfind_or_faildoes.
§It does not authorise
Binding finds the row; it does not ask whether this caller may have it. A draft post binds happily for a stranger. Follow it with a policy — or, better, with a request contract that authorises before the action runs at all.
Tuple Fields§
§0: MImplementations§
Trait Implementations§
Source§impl<M: Model> FromRequest for Bound<M>
impl<M: Model> FromRequest for Bound<M>
Source§fn from_request(request: Arc<Request>) -> BoxedFuture<Result<Self>>
fn from_request(request: Arc<Request>) -> BoxedFuture<Result<Self>>
Build
Self from the request, or fail with the error the client should
see (a 400 for a malformed body, a 422 for a failed contract).Auto Trait Implementations§
impl<M> Freeze for Bound<M>where
M: Freeze,
impl<M> RefUnwindSafe for Bound<M>where
M: RefUnwindSafe,
impl<M> Send for Bound<M>
impl<M> Sync for Bound<M>
impl<M> Unpin for Bound<M>where
M: Unpin,
impl<M> UnsafeUnpin for Bound<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for Bound<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
A human-readable name, used by wildcard listeners and log output.
Always the Rust type path; see the trait docs.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.