pub struct RwLockReadGuard<'a, T> { /* private fields */ }Implementations§
Source§impl<'a, T> RwLockReadGuard<'a, T>where
T: Serialize + DeserializeOwned,
impl<'a, T> RwLockReadGuard<'a, T>where
T: Serialize + DeserializeOwned,
Methods from Deref<Target = Generic<T>>§
Sourcepub fn cached(&self) -> Option<&T>
pub fn cached(&self) -> Option<&T>
The get method returns a reference to the value stored in the type.
Examples found in repository?
examples/2services.rs (line 12)
5fn main() {
6 thread::scope(|s| {
7 let client = redis::Client::open("redis://localhost:6379").unwrap();
8 let client2 = client.clone();
9
10 let t1 = s.spawn(move || {
11 let mut string = String::with_value("Hello".to_string(), "test", client);
12 println!("Thread1: {}", string.cached().unwrap());
13 assert_eq!(string, "Hello");
14 sleep(std::time::Duration::from_secs(1));
15 string.store("World".to_string());
16 println!("Thread1: {}", string.cached().unwrap());
17 assert_eq!(string, "World");
18 });
19
20 let t2 = s.spawn(move || {
21 sleep(std::time::Duration::from_micros(100));
22 let mut string = String::with_load("test", client2);
23 println!("Thread2: {}", string.cached().unwrap());
24 assert_eq!(string, "Hello");
25 sleep(std::time::Duration::from_secs(2));
26 string.acquire();
27 println!("Thread2: {}", string.cached().unwrap());
28 assert_eq!(string, "World");
29 });
30 t1.join().expect("Failed to join thread1");
31 t2.join().expect("Failed to join thread2");
32 });
33}Trait Implementations§
Source§impl<'a, T> Deref for RwLockReadGuard<'a, T>
impl<'a, T> Deref for RwLockReadGuard<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for RwLockReadGuard<'a, T>where
T: Freeze,
impl<'a, T> !RefUnwindSafe for RwLockReadGuard<'a, T>
impl<'a, T> Send for RwLockReadGuard<'a, T>
impl<'a, T> Sync for RwLockReadGuard<'a, T>where
T: Sync,
impl<'a, T> Unpin for RwLockReadGuard<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for RwLockReadGuard<'a, T>
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