mirror of
https://github.com/actix/actix-web.git
synced 2024-11-08 18:19:30 +00:00
update doc strings
This commit is contained in:
parent
64d867d9a1
commit
626999bcc9
1 changed files with 23 additions and 5 deletions
|
@ -20,6 +20,23 @@ use httpresponse::HttpResponse;
|
||||||
use middlewares::{Middleware, Started, Response};
|
use middlewares::{Middleware, Started, Response};
|
||||||
|
|
||||||
/// The helper trait to obtain your session data from a request.
|
/// The helper trait to obtain your session data from a request.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use actix_web::*;
|
||||||
|
/// use actix_web::middlewares::RequestSession;
|
||||||
|
///
|
||||||
|
/// fn index(mut req: HttpRequest) -> Result<&'static str> {
|
||||||
|
/// // access session data
|
||||||
|
/// if let Some(count) = req.session().get::<i32>("counter")? {
|
||||||
|
/// req.session().set("counter", count+1)?;
|
||||||
|
/// } else {
|
||||||
|
/// req.session().set("counter", 1)?;
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// Ok("Welcome!")
|
||||||
|
/// }
|
||||||
|
/// # fn main() {}
|
||||||
|
/// ```
|
||||||
pub trait RequestSession {
|
pub trait RequestSession {
|
||||||
fn session(&mut self) -> Session;
|
fn session(&mut self) -> Session;
|
||||||
}
|
}
|
||||||
|
@ -101,14 +118,15 @@ unsafe impl Sync for SessionImplBox {}
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate actix;
|
/// # extern crate actix;
|
||||||
/// # extern crate actix_web;
|
/// # extern crate actix_web;
|
||||||
|
/// # use actix_web::middlewares::{SessionStorage, CookieSessionBackend};
|
||||||
/// use actix_web::*;
|
/// use actix_web::*;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let app = Application::new()
|
/// let app = Application::new().middleware(
|
||||||
/// .middleware(middlewares::SessionStorage::new( // <- create session middlewares
|
/// SessionStorage::new( // <- create session middlewares
|
||||||
/// middlewares::CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend
|
/// CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend
|
||||||
/// .secure(false)
|
/// .secure(false)
|
||||||
/// .finish())
|
/// .finish())
|
||||||
/// );
|
/// );
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
Loading…
Reference in a new issue