Struct Extension
struct Extension<T>(2)
Extractor and response for extensions.
As extractor
This is commonly used to share state across handlers.
use ;
use Arc;
// Some shared state used throughout our application
async
let state = new;
let app = new.route
// Add middleware that inserts the state into all incoming request's
// extensions.
.layer;
# let _: Router = app;
If the extension is missing it will reject the request with a 500 Internal Server Error response. Alternatively, you can use Option<Extension<T>> to
make the extension extractor optional.
As response
Response extensions can be used to share state with middleware.
use ;
async
;
Implementations
impl<H, T> HandlerWithoutStateExt for Extension<T>
fn into_service(self: Self) -> HandlerService<H, T, ()>fn into_make_service(self: Self) -> IntoMakeService<HandlerService<H, T, ()>>fn into_make_service_with_connect_info<C>(self: Self) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
impl<P, T> Receiver for Extension<T>
impl<R> Rng for Extension<T>
impl<R> TryCryptoRng for Extension<T>
impl<R> TryRngCore for Extension<T>
fn try_next_u32(self: &mut Self) -> Result<u32, <R as TryRngCore>::Error>fn try_next_u64(self: &mut Self) -> Result<u64, <R as TryRngCore>::Error>fn try_fill_bytes(self: &mut Self, dst: &mut [u8]) -> Result<(), <R as TryRngCore>::Error>
impl<S, T> FromRequest for Extension<T>
fn from_request(req: Request<Body>, state: &S) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
impl<S, T> Layer for Extension<T>
fn layer(self: &Self, inner: S) -> <Self as >::Service
impl<T> Any for Extension<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Extension<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Extension<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Extension<T>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> CryptoRng for Extension<T>
impl<T> Deref for Extension<T>
fn deref(self: &Self) -> &<Self as >::Target
impl<T> DerefMut for Extension<T>
fn deref_mut(self: &mut Self) -> &mut <Self as >::Target
impl<T> Freeze for Extension<T>
impl<T> From for Extension<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> FromRef for Extension<T>
fn from_ref(input: &T) -> T
impl<T> Instrument for Extension<T>
impl<T> IntoResponse for Extension<T>
fn into_response(self: Self) -> Response
impl<T> IntoResponseParts for Extension<T>
fn into_response_parts(self: Self, res: ResponseParts) -> Result<ResponseParts, <Self as >::Error>
impl<T> RefUnwindSafe for Extension<T>
impl<T> RngCore for Extension<T>
fn next_u32(self: &mut Self) -> u32fn next_u64(self: &mut Self) -> u64fn fill_bytes(self: &mut Self, dst: &mut [u8])
impl<T> Same for Extension<T>
impl<T> Send for Extension<T>
impl<T> Sync for Extension<T>
impl<T> ToOwned for Extension<T>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> Unpin for Extension<T>
impl<T> UnwindSafe for Extension<T>
impl<T> WithSubscriber for Extension<T>
impl<T, S> FromRequestParts for Extension<T>
async fn from_request_parts(req: &mut Parts, _state: &S) -> Result<Self, <Self as >::Rejection>
impl<T, S> OptionalFromRequestParts for Extension<T>
async fn from_request_parts(req: &mut Parts, _state: &S) -> Result<Option<Self>, <Self as >::Rejection>
impl<T, U> Into for Extension<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Extension<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Extension<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::clone::Clone> Clone for Extension<T>
fn clone(self: &Self) -> Extension<T>
impl<T: $crate::default::Default> Default for Extension<T>
fn default() -> Extension<T>
impl<T: $crate::fmt::Debug> Debug for Extension<T>
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl<T: $crate::marker::Copy> Copy for Extension<T>
impl<V, T> VZip for Extension<T>
fn vzip(self: Self) -> V