pub struct ExtractVersion(pub String);
Expand description
This is a custom extractor for Axum that extracts the version, via the X-Version
request header.
If the X-Version
header is present, it returns it.
If the X-Version
header is not present, it defaults to latest
.
§Links
https://docs.rs/axum/latest/axum/index.html https://docs.rs/axum/latest/axum/extract/index.html#defining-custom-extractors
§Author
François GRUCHALA francois@nebeto.xyz
§Examples
use axum::{routing::get, Router};
use version_middleware::ExtractVersion;
async fn handler(ExtractVersion(version): ExtractVersion) {
println!("Version: {}", version);
}
let app = Router::<()>::new().route("/foo", get(handler));
Tuple Fields§
§0: String
Trait Implementations§
Source§impl Clone for ExtractVersion
impl Clone for ExtractVersion
Source§fn clone(&self) -> ExtractVersion
fn clone(&self) -> ExtractVersion
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ExtractVersion
impl Debug for ExtractVersion
Source§impl<S> FromRequestParts<S> for ExtractVersion
impl<S> FromRequestParts<S> for ExtractVersion
Auto Trait Implementations§
impl Freeze for ExtractVersion
impl RefUnwindSafe for ExtractVersion
impl Send for ExtractVersion
impl Sync for ExtractVersion
impl Unpin for ExtractVersion
impl UnwindSafe for ExtractVersion
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§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.
Source§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.