From e67e4b027d6030feabac3eeb0b4cf068b26b901b Mon Sep 17 00:00:00 2001 From: "daniel.hartig" Date: Fri, 10 Jun 2022 18:43:00 -0500 Subject: [PATCH] Added function to create an empty session for testing --- actix-session/src/session.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/actix-session/src/session.rs b/actix-session/src/session.rs index 2aa3bae68..87505bda1 100644 --- a/actix-session/src/session.rs +++ b/actix-session/src/session.rs @@ -75,6 +75,20 @@ struct SessionInner { } impl Session { + + /// Create an empty session. Appropriate for testing. + /// + /// This session wraps an empty state map and status. It can be instantiated for testing purposes. + pub fn empty() -> Session { + let inner = SessionInner{ + state: HashMap::new(), + status: SessionStatus::default(), + }; + Session(Rc::new(RefCell::new(inner))) + } + + + /// Get a `value` from the session. /// /// It returns an error if it fails to deserialize as `T` the JSON value associated with `key`.