poison-guard

Utilities for maintaining sane state in the presence of panics and failures. It's a bit like the poison and with_drop crates.

What is poisoning?

Poisoning is a general strategy for keeping state consistent by blocking direct access to state if a previous user did something unexpected with it.

Use cases

Getting started

Add poison-guard to your Cargo.toml:

toml [dependencies.poison-guard] version = "0.1.0"

Then wrap your state in a Poison<T>:

```rust use poison_guard::Poison;

pub struct MyData { state: Poison, } ```

When you want to access your state, you can acquire a poison guard:

```rust let mut guard = Poison::onunwind(&mut mydata.state).unwrap();

dosomethingwith_state(&mut guard); ```

If a panic unwinds through a poison guard it'll panic the value, blocking future callers from accessing it. Poisoned values can be recovered, or the original failure can be propagated to those future callers.

For more details, see the documentation.