[−][src]Struct actix_web::web::Data
Application data.
Application data is an arbitrary data attached to the app.
Application data is available to all routes and could be added
during application configuration process
with App::data()
method.
Application data could be accessed by using Data<T>
extractor where T
is data type.
Note: http server accepts an application factory rather than
an application instance. Http server constructs an application
instance for each thread, thus application data must be constructed
multiple times. If you want to share data between different
threads, a shareable object should be used, e.g. Send + Sync
. Application
data does not need to be Send
or Sync
. Internally Data
instance
uses Arc
.
If route data is not set for a handler, using Data<T>
extractor would
cause Internal Server Error response.
use std::cell::Cell; use actix_web::{web, App}; struct MyData { counter: Cell<usize>, } /// Use `Data<T>` extractor to access data in handler. fn index(data: web::Data<MyData>) { data.counter.set(data.counter.get() + 1); } fn main() { let app = App::new() // Store `MyData` in application storage. .data(MyData{ counter: Cell::new(0) }) .service( web::resource("/index.html").route( web::get().to(index))); }
Methods
impl<T> Data<T>
[src]
Trait Implementations
impl<T: 'static> FromRequest for Data<T>
[src]
type Config = ()
Configuration for this extractor
type Error = Error
The associated error which can be returned.
type Future = Result<Self, Error>
Future that resolves to a Self
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
[src]
fn extract(req: &HttpRequest) -> Self::Future
[src]
Convert request to a Self Read more
fn configure<F>(f: F) -> Self::Config where
F: FnOnce(Self::Config) -> Self::Config,
[src]
F: FnOnce(Self::Config) -> Self::Config,
Create and configure config instance.
impl<T> Clone for Data<T>
[src]
fn clone(&self) -> Data<T>
[src]
default fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T> Deref for Data<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.