Macro rocket::request::local_cache[][src]

pub macro local_cache($request:expr, $v:expr $(,)?) {
    ...
}
Expand description

Store and immediately retrieve a value $v in $request’s local cache using a locally generated anonymous type to avoid type conflicts.

Example

use rocket::request::local_cache;

// The first store into local cache for a given type wins.
assert_eq!(request.local_cache(|| String::from("hello")), "hello");

// The following returns the cached, previously stored value for the type.
assert_eq!(request.local_cache(|| String::from("goodbye")), "hello");

// This shows that we cannot cache different values of the same type; we
// _must_ use a proxy type. To avoid the need to write these manually, use
// `local_cache!`, which generates one of the fly.
assert_eq!(local_cache!(request, String::from("hello")), "hello");
assert_eq!(local_cache!(request, String::from("goodbye")), "goodbye");