Struct drone_core::sync::RwLock [] [src]

pub struct RwLock<T> { /* fields omitted */ }

A reader-writer lock.

This lock supports only try_read and try_write method, and hence never blocks.

Methods

impl<T> RwLock<T>
[src]

[src]

Creates a new instance of an RwLock<T> which is unlocked.

Examples

use drone_core::sync::RwLock;

let lock = RwLock::new(5);

[src]

Attempts to acquire this rwlock with shared read access.

If the access could not be granted at this time, then Err is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.

This function does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

Examples

use drone_core::sync::RwLock;

let lock = RwLock::new(1);

match lock.try_read() {
  Some(n) => assert_eq!(*n, 1),
  None => unreachable!(),
};

[src]

Attempts to lock this rwlock with exclusive write access.

If the lock could not be acquired at this time, then Err is returned. Otherwise, an RAII guard is returned which will release the lock when it is dropped.

This function does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

Examples

use drone_core::sync::RwLock;

let lock = RwLock::new(1);

let n = lock.try_read().unwrap();
assert_eq!(*n, 1);

assert!(lock.try_write().is_none());

[src]

Consumes this RwLock, returning the underlying data.

Examples

use drone_core::sync::RwLock;

let lock = RwLock::new(String::new());
{
  let mut s = lock.try_write().unwrap();
  *s = "modified".to_owned();
}
assert_eq!(lock.into_inner(), "modified");

[src]

Returns a mutable reference to the underlying data.

Since this call borrows the RwLock mutably, no actual locking needs to take place --- the mutable borrow statically guarantees no locks exist.

Examples

use drone_core::sync::RwLock;

let mut lock = RwLock::new(0);
*lock.get_mut() = 10;
assert_eq!(*lock.try_read().unwrap(), 10);

Trait Implementations

impl<T: Send> Send for RwLock<T>
[src]

impl<T: Send + Sync> Sync for RwLock<T>
[src]

impl<T: Default> Default for RwLock<T>
[src]

[src]

Creates a new RwLock<T>, with the Default value for T.