logo
pub struct Depot { /* private fields */ }
Expand description

Depot if for store temp data of current request. Each handler can read or write data to it.

Example

use salvo_core::prelude::*;

#[handler]
async fn set_user(req: &mut Request, depot: &mut Depot, res: &mut Response, ctrl: &mut FlowCtrl) {
    depot.insert("user", "client");
    ctrl.call_next(req, depot, res).await;
}
#[handler]
async fn hello_world(depot: &mut Depot) -> String {
    format!("Hello {}", depot.get::<&str>("user").map(|s|*s).unwrap_or_default())
}
#[tokio::main]
async fn main() {
    let router = Router::new().hoop(set_user).handle(hello_world);
    Server::new(TcpListener::bind("127.0.0.1:7878")).serve(router).await;
}

Implementations

Creates an empty Depot.

The depot is initially created with a capacity of 0, so it will not allocate until it is first inserted into.

Get reference to depot inner map.

Creates an empty Depot with the specified capacity.

The depot will be able to hold at least capacity elements without reallocating. If capacity is 0, the depot will not allocate.

Returns the number of elements the depot can hold without reallocating.

Inject a value into the depot.

Obtain a reference to a value previous inject to the depot.

Inserts a key-value pair into the depot.

Check is there a value stored in depot with this key.

Immutably borrows value from depot, returing none if value is not present in depot.

Mutably borrows value from depot, returing none if value is not present in depot.

Take value from depot container.

Transfer all data to a new instance.

Trait Implementations

Get basic auth username reference.

Gets the CSRF token for inclusion in an HTTP request header, a query parameter, or a form field. Read more

Gets the name of the header in which to returns the CSRF token, if the CSRF token is being returned in a header. Read more

Gets the name of the query param in which to returns the CSRF token, if the CSRF token is being returned in a query param. Read more

Gets the name of the form field in which to returns the CSRF token, if the CSRF token is being returned in a form field. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

get jwt auth token reference from depot.

get jwt auth decoded data from depot.

get jwt auth state from depot.

Set session

Take session

Get session reference

Get session mutable reference

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more