pub struct Extension<T>(pub T);Expand description
Inserting anything into contexts as a Layer or extracting anything as an extractor
§Examples
ⓘ
use volo_http::{
server::route::{get, Router},
utils::Extension,
};
#[derive(Clone)]
struct State {
foo: String,
}
// A handler for extracting the `State` from `Extension`
async fn show_state(Extension(state): Extension<State>) -> String {
state.foo
}
let router: Router = Router::new()
.route("/", get(show_state))
// Use `Extension` as a `Layer`
.layer(Extension(State {
foo: String::from("bar"),
}));Tuple Fields§
§0: TTrait Implementations§
Source§impl<T> FromContext for Extension<T>
Available on crate feature server only.
impl<T> FromContext for Extension<T>
Available on crate feature
server only.impl<T: Copy> Copy for Extension<T>
Auto Trait Implementations§
impl<T> Freeze for Extension<T>where
T: Freeze,
impl<T> RefUnwindSafe for Extension<T>where
T: RefUnwindSafe,
impl<T> Send for Extension<T>where
T: Send,
impl<T> Sync for Extension<T>where
T: Sync,
impl<T> Unpin for Extension<T>where
T: Unpin,
impl<T> UnwindSafe for Extension<T>where
T: 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