mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
added app_data() method
This commit is contained in:
parent
237bfba1ed
commit
cef3dc3586
@ -6,6 +6,11 @@
|
||||
|
||||
* `App::configure()` allow to offload app configuration to different methods
|
||||
|
||||
* Added `ServiceRequest::app_data()`, returns `Data<T>`
|
||||
|
||||
* Added `ServiceFromRequest::app_data()`, returns `Data<T>`
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
* Move multipart support to actix-multipart crate
|
||||
|
@ -13,7 +13,7 @@ use actix_router::{Path, Resource, Url};
|
||||
use futures::future::{ok, FutureResult, IntoFuture};
|
||||
|
||||
use crate::config::{AppConfig, ServiceConfig};
|
||||
use crate::data::RouteData;
|
||||
use crate::data::{Data, RouteData};
|
||||
use crate::request::HttpRequest;
|
||||
use crate::rmap::ResourceMap;
|
||||
|
||||
@ -173,6 +173,16 @@ impl<P> ServiceRequest<P> {
|
||||
pub fn app_config(&self) -> &AppConfig {
|
||||
self.req.config()
|
||||
}
|
||||
|
||||
/// Get an application data stored with `App::data()` method during
|
||||
/// application configuration.
|
||||
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
|
||||
if let Some(st) = self.req.config().extensions().get::<Data<T>>() {
|
||||
Some(st.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Resource<Url> for ServiceRequest<P> {
|
||||
@ -270,6 +280,16 @@ impl<P> ServiceFromRequest<P> {
|
||||
ServiceResponse::new(self.req, err.into().into())
|
||||
}
|
||||
|
||||
/// Get an application data stored with `App::data()` method during
|
||||
/// application configuration.
|
||||
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
|
||||
if let Some(st) = self.req.config().extensions().get::<Data<T>>() {
|
||||
Some(st.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Load route data. Route data could be set during
|
||||
/// route configuration with `Route::data()` method.
|
||||
pub fn route_data<T: 'static>(&self) -> Option<&RouteData<T>> {
|
||||
|
Loading…
Reference in New Issue
Block a user