pub struct Session(/* private fields */);Expand description
The high-level interface you use to modify session data.
Session object could be obtained with
RequestSession::session
method. RequestSession trait is implemented for HttpRequest.
use ntex_session::Session;
use ntex::web::*;
fn index(session: Session) -> Result<&'static str, Error> {
// access session data
if let Some(count) = session.get::<i32>("counter")? {
session.set("counter", count + 1)?;
} else {
session.set("counter", 1)?;
}
Ok("Welcome!")
}Implementations§
Source§impl Session
impl Session
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>, Error>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>, Error>
Get a value from the session.
Sourcepub fn set<T: Serialize>(&self, key: &str, value: T) -> Result<(), Error>
pub fn set<T: Serialize>(&self, key: &str, value: T) -> Result<(), Error>
Set a value from the session.
pub fn set_session<Err>( data: impl Iterator<Item = (String, String)>, req: &WebRequest<Err>, )
pub fn get_changes( res: &mut WebResponse, ) -> (SessionStatus, Option<impl Iterator<Item = (String, String)> + use<>>)
Trait Implementations§
Source§impl<Err> FromRequest<Err> for Session
Extractor implementation for Session type.
impl<Err> FromRequest<Err> for Session
Extractor implementation for Session type.
use ntex_session::Session;
fn index(session: Session) -> Result<&'static str, ntex::web::Error> {
// access session data
if let Some(count) = session.get::<i32>("counter")? {
session.set("counter", count + 1)?;
} else {
session.set("counter", 1)?;
}
Ok("Welcome!")
}Source§type Error = Infallible
type Error = Infallible
The associated error which can be returned.
Source§async fn from_request(
req: &HttpRequest,
_: &mut Payload,
) -> Result<Session, Infallible>
async fn from_request( req: &HttpRequest, _: &mut Payload, ) -> Result<Session, Infallible>
Convert request to a Self
Auto Trait Implementations§
impl Freeze for Session
impl !RefUnwindSafe for Session
impl !Send for Session
impl !Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more