Struct persistent::Write [] [src]

pub struct Write<P: Key> {
    // some fields omitted
}

Middleware for data that persists between Requests for data which mostly needs to be written instead of read.

The data is stored behind a Mutex, so only one request at a time can access the data. This is more performant than State in the case where most uses of the data require a write lock.

Write 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.

Write also implements Plugin, so the data stored within can be accessed through request.get::<Write<P>>() as an Arc<Mutex<P::Value>>.

Methods

impl<P: Key> Write<P> where P::Value: Send

fn both(start: P::Value) -> (Write<P>, Write<P>)

Construct a new pair of Write that can be passed directly to Chain::link.

The data is initialized with the passed-in value.

fn one(start: P::Value) -> Write<P>

Construct a new Write 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 Write<P> where P::Value: Send

fn clone(&self) -> Write<P>

fn clone_from(&mut self, source: &Self)

impl<P: Key> Key for Write<P> where P::Value: 'static

type Value = Arc<Mutex<P::Value>>

impl<'a, 'b, P: Key> Plugin<Request<'a, 'b>> for Write<P> where P::Value: Send

type Error = PersistentError

fn eval(req: &mut Request<'a, 'b>) -> Result<Arc<Mutex<P::Value>>, PersistentError>

impl<P: Key> BeforeMiddleware for Write<P> where P::Value: Send

fn before(&self, req: &mut Request) -> IronResult<()>

fn catch(&self, &mut Request, err: IronError) -> Result<(), IronError>

impl<P: Key> AfterMiddleware for Write<P> where P::Value: Send

fn after(&self, _: &mut Request, res: Response) -> IronResult<Response>

fn catch(&self, &mut Request, err: IronError) -> Result<Response, IronError>