Struct drone_core::sync::Mutex [] [src]

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

A mutual exclusion primitive useful for protecting shared data.

This mutex supports only try_lock method, and hence never blocks.

Methods

impl<T> Mutex<T>
[src]

[src]

Creates a new mutex in an unlocked state ready for use.

Examples

use drone_core::sync::Mutex;

let mutex = Mutex::new(0);

[src]

Attempts to acquire this lock.

If the lock could not be acquired at this time, then None is returned. Otherwise, a RAII guard is returned. The lock will be unlocked when the guard is dropped.

Examples

use drone_core::sync::Mutex;

let mutex = Mutex::new(1);

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

[src]

Consumes this mutex, returning the underlying data.

Examples

use drone_core::sync::Mutex;

let mutex = Mutex::new(0);
assert_eq!(mutex.into_inner(), 0);

[src]

Returns a mutable reference to the underlying data.

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

Examples

use drone_core::sync::Mutex;

let mut mutex = Mutex::new(0);
*mutex.get_mut() = 10;
assert_eq!(*mutex.try_lock().unwrap(), 10);

Trait Implementations

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

impl<T: Send> Sync for Mutex<T>
[src]

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

[src]

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