1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 17:07:01 +02:00

unify route and app data, it allows to provide global extractor config #775

This commit is contained in:
Nikolay Kim
2019-05-04 19:43:49 -07:00
parent 01cfcf3b75
commit fa78da8156
18 changed files with 292 additions and 426 deletions

View File

@@ -1,4 +1,5 @@
use std::cell::{Ref, RefMut};
use std::rc::Rc;
use std::{fmt, net};
use actix_http::body::{Body, MessageBody, ResponseBody};
@@ -180,12 +181,18 @@ impl ServiceRequest {
/// 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.app_config().extensions().get::<Data<T>>() {
if let Some(st) = self.req.0.app_data.get::<Data<T>>() {
Some(st.clone())
} else {
None
}
}
#[doc(hidden)]
/// Set new app data container
pub fn set_data_container(&mut self, extensions: Rc<Extensions>) {
Rc::get_mut(&mut self.req.0).unwrap().app_data = extensions;
}
}
impl Resource<Url> for ServiceRequest {