Struct ntex_session::Session
source · 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)>>)
Trait Implementations§
source§impl<Err> FromRequest<Err> for Session
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!")
}§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 !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