1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! This crate extends `Mutex`es and `RwLock`s wrapping references with static lifetimes to leak these raw underlying references.
//! This can be useful to safely obtain a static mutable reference without using any unsafe code when interacting with a legacy C project via FFI.
//!
//! ```
//! # use lazy_static::lazy_static;
//! # use std::sync::{RwLock, RwLockWriteGuard};
//! use static_leak::RwLockWriteGuardExtension;
//!
//! lazy_static! {
//! static ref VAR: RwLock<i8> = RwLock::new(42);
//! }
//!
//! fn bar(_: &'static mut i8) {}
//!
//! fn main() {
//! bar(RwLockWriteGuard::leak(VAR.write().unwrap()));
//! }
//! ```
//!
//! This crate supports implementations from the following crates, which are activated through the respective feature flags:
//! * std
//! * async-std
//! * spin
/// Improves the support for static references of MutexGuard.