Struct persistent::State
[−]
[src]
pub struct State<P: Key> { // some fields omitted }
Middleware for data that persists between requests with read and write capabilities.
The data is stored behind a RwLock
, so multiple read locks
can be taken out concurrently.
If most threads need to take out a write lock, you may want to
consider Write
, which stores the data behind a Mutex
, which
has a faster locking speed.
State
can be linked as BeforeMiddleware
to add data to the Request
extensions and it can be linked as an AfterMiddleware
to add data to
the Response
extensions.
State
also implements Plugin
, so the data stored within can be
accessed through request.get::<State<P>>()
as an Arc<RwLock<P::Value>>
.
Methods
impl<P: Key> State<P> where P::Value: Send + Sync
[src]
fn both(start: P::Value) -> (State<P>, State<P>)
Construct a new pair of State
that can be passed directly to Chain::link
.
The data is initialized with the passed-in value.
fn one(start: P::Value) -> State<P>
Construct a new State
that can be passed directly to
Chain::link_before
or Chain::link_after
.
The data is initialized with the passed-in value.
Trait Implementations
impl<P: Key> Clone for State<P> where P::Value: Send + Sync
[src]
fn clone(&self) -> State<P>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<P: Key> Key for State<P> where P::Value: 'static
[src]
impl<'a, 'b, P: Key> Plugin<Request<'a, 'b>> for State<P> where P::Value: Send + Sync
[src]
type Error = PersistentError
The error type associated with this plugin.
fn eval(req: &mut Request<'a, 'b>) -> Result<Arc<RwLock<P::Value>>, PersistentError>
Create the plugin from an instance of the extended type. Read more
impl<P: Key> BeforeMiddleware for State<P> where P::Value: Send + Sync
[src]
fn before(&self, req: &mut Request) -> IronResult<()>
Do whatever work this middleware should do with a Request
object.
fn catch(&self, &mut Request, err: IronError) -> Result<(), IronError>
Respond to an error thrown by a previous BeforeMiddleware
. Read more
impl<P: Key> AfterMiddleware for State<P> where P::Value: Send + Sync
[src]
fn after(&self, _: &mut Request, res: Response) -> IronResult<Response>
Do whatever post-processing this middleware should do.
fn catch(&self, &mut Request, err: IronError) -> Result<Response, IronError>
Respond to an error thrown by previous AfterMiddleware
, the Handler
, or a BeforeMiddleware
. Read more