# Struct std::sync::StaticRwLock [−] [src]

    pub struct StaticRwLock {
        // some fields omitted
    }

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Structure representing a statically allocated RwLock.

This structure is intended to be used inside of a `static` and will provide automatic global access as well as lazy initialization. The internal resources of this RwLock, however, must be manually deallocated.

# Examples

#![feature(static_rwlock)] fn main() { use std::sync::{StaticRwLock, RW_LOCK_INIT}; static LOCK: StaticRwLock = RW_LOCK_INIT; { let _g = LOCK.read().unwrap(); // ... shared read access } { let _g = LOCK.write().unwrap(); // ... exclusive write access } unsafe { LOCK.destroy() } // free all resources }

    #![feature(static_rwlock)]

    use std::sync::{StaticRwLock, RW_LOCK_INIT};

    static LOCK: StaticRwLock = RW_LOCK_INIT;

    {
        let _g = LOCK.read().unwrap();
        // ... shared read access
    }
    {
        let _g = LOCK.write().unwrap();
        // ... exclusive write access
    }
    unsafe { LOCK.destroy() } // free all resources

## Methods

### `impl StaticRwLock`

#### `const fn new() -> StaticRwLock`

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Creates a new rwlock.

#### `fn read(&'static self) -> LockResult<RwLockReadGuard<'static, ()>>`

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Locks this rwlock with shared read access, blocking the current thread until it can be acquired.

See `RwLock::read`.

#### `fn try_read(&'static self) -> TryLockResult<RwLockReadGuard<'static, ()>>`

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Attempts to acquire this lock with shared read access.

See `RwLock::try_read`.

#### `fn write(&'static self) -> LockResult<RwLockWriteGuard<'static, ()>>`

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.

See `RwLock::write`.

#### `fn try_write(&'static self) -> TryLockResult<RwLockWriteGuard<'static, ()>>`

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Attempts to lock this rwlock with exclusive write access.

See `RwLock::try_write`.

#### `unsafe fn destroy(&'static self)`

Unstable (`static_rwlock` #27717)

: may be merged with RwLock in the future

Deallocates all resources associated with this static lock.

This method is unsafe to call as there is no guarantee that there are no active users of the lock, and this also doesn't prevent any future users of this lock. This method is required to be called to not leak memory on all platforms.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize`)