1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-07-03 20:45:46 +00:00

feat: add access to the session also from immutable references (#1225)

This commit is contained in:
tglman 2019-12-20 07:59:07 +00:00 committed by Nikolay Kim
parent 1d12ba9d5f
commit fbbb4a86e9
2 changed files with 9 additions and 4 deletions

View file

@ -1,5 +1,10 @@
# Changes
## [0.3.0-alpha.4] - 2019-12-xx
* Allow access to sessions also from not mutable references to the request
## [0.3.0-alpha.3] - 2019-12-xx
* Add access to the session from RequestHead for use of session from guard methods

View file

@ -85,23 +85,23 @@ pub struct Session(Rc<RefCell<SessionInner>>);
/// Helper trait that allows to get session
pub trait UserSession {
fn get_session(&mut self) -> Session;
fn get_session(&self) -> Session;
}
impl UserSession for HttpRequest {
fn get_session(&mut self) -> Session {
fn get_session(&self) -> Session {
Session::get_session(&mut *self.extensions_mut())
}
}
impl UserSession for ServiceRequest {
fn get_session(&mut self) -> Session {
fn get_session(&self) -> Session {
Session::get_session(&mut *self.extensions_mut())
}
}
impl UserSession for RequestHead {
fn get_session(&mut self) -> Session {
fn get_session(&self) -> Session {
Session::get_session(&mut *self.extensions_mut())
}
}