pub struct Htmx(pub bool);Expand description
Extractor telling whether htmx sent the request: Htmx(true) when it has HX-Request: true.
Use it to answer with an HTML fragment instead of a full page or a
redirect. It never rejects: any other value or a missing header is
Htmx(false). Requires the html feature.
§Examples
use axum::response::{Html, IntoResponse, Redirect, Response};
use ocre::Htmx;
async fn like(Htmx(is_htmx): Htmx) -> Response {
if is_htmx {
Html("<button disabled>Liked</button>").into_response()
} else {
Redirect::to("/").into_response()
}
}Tuple Fields§
§0: boolTrait Implementations§
impl Copy for Htmx
Source§impl<S: Send + Sync> FromRequestParts<S> for Htmx
impl<S: Send + Sync> FromRequestParts<S> for Htmx
Source§type Rejection = Infallible
type Rejection = Infallible
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§async fn from_request_parts(
parts: &mut Parts,
_state: &S,
) -> Result<Self, Self::Rejection>
async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<Self, Self::Rejection>
Perform the extraction.
Auto Trait Implementations§
impl Freeze for Htmx
impl RefUnwindSafe for Htmx
impl Send for Htmx
impl Sync for Htmx
impl Unpin for Htmx
impl UnsafeUnpin for Htmx
impl UnwindSafe for Htmx
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.