Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ tokio = { version = "1", features = ["full"] }

[features]
default = []
# Enabling will force checks for the unchecked types. Making them perform exactly like
# the checked versions. This is intended to only be used for debug purposes.
checked = []

[package.metadata.docs.rs]
all-features = false
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,30 @@ This fails because the reference to `ref_value` isn’t `'static`.
## Example

```rust
use scoped_static::{ScopeGuard, Scoped};
use scoped_static::{scoped_static, ScopedRefGuard};

#[tokio::main]
async fn main() {
let value = Box::new(1.0);
let ref_value = &value;
// `guard` ensures no derived "lifted" values exist when dropped
let guard = ScopeGuard::new(ref_value);
// `guard` ensures no derived "lifted" values exist when dropped.
// The type is `&mut ScopedRefGuard<'_, Box<NonCopy>>`
let guard = scoped_static!(ref_value);
// `lifted` holds a `'static` reference to `'ref_value`
let lifted: Scoped<Box<f64>> = guard.lift();
// The type is `ScopedRef<Box<f64>>`
let lifted = guard.lift();
tokio::spawn(async move {
// lifted moved here
// `lifted` moved here
let value = **lifted + 1.0;
assert_eq!(value, 2.0);
// lifted dropped
// `lifted` dropped
})
.await
.unwrap();
// guard dropped
// Forgetting has no effect since `guard` is a reference
std::mem::forget(guard); // SAFE
// `guard` dropped
}
```

See [ScopeGuard](https://docs.rs/scoped_static/latest/scoped_static/struct.ScopeGuard.html) and
[UncheckedScopeGuard](https://docs.rs/scoped_static/latest/scoped_static/struct.UncheckedScopeGuard.html) for more info.
See [ScopeGuard](https://docs.rs/scoped_static/latest/scoped_static/struct.ScopeGuard.html) for more info.
Loading
Loading