6 releases

Uses old Rust 2015

0.1.6 Sep 25, 2021
0.1.5 Jul 31, 2020
0.1.4 Aug 1, 2018

#575 in Rust patterns

Download history 35228/week @ 2025-06-09 40369/week @ 2025-06-16 38541/week @ 2025-06-23 36474/week @ 2025-06-30 38791/week @ 2025-07-07 37744/week @ 2025-07-14 40902/week @ 2025-07-21 35540/week @ 2025-07-28 62944/week @ 2025-08-04 63582/week @ 2025-08-11 56615/week @ 2025-08-18 61884/week @ 2025-08-25 48961/week @ 2025-09-01 52591/week @ 2025-09-08 56904/week @ 2025-09-15 49722/week @ 2025-09-22

216,976 downloads per month
Used in 605 crates (20 directly)

MIT/Apache

7KB
142 lines

drop_bomb

drop_bomb provides two types, DropBomb and DebugDropBomb, which panic in drop with a specified message unless defused. This is useful as a building-block for runtime-checked linear types.

For example, one can build a variant of BufWriter which enforces handling of errors during flush.

extern crate drop_bomb;

use std::io::{Write, BufWriter, Result};
use drop_bomb::DropBomb;

struct CheckedBufWriter<W: Write> {
    inner: BufWriter<W>,
    bomb: DropBomb,
}

impl<W: Write> CheckedBufWriter<W> {
    fn new(inner: BufWriter<W>) -> CheckedBufWriter<W> {
        let bomb = DropBomb::new(
            "CheckedBufWriter must be explicitly closed \
             to handle potential errors on flush"
        );
        CheckedBufWriter { inner, bomb }
    }

    fn close(mut self) -> Result<()> {
        self.bomb.defuse();
        self.inner.flush()?;
        Ok(())
    }
}

Notes:

  • Bombs do nothing if a thread is already panicking.
  • When #[cfg(debug_assertions)] is disabled, DebugDropBomb is always defused and has a zero size.

drop_bomb

Build Status Crates.io API reference

A runtime guard for (protecting your precious bodily fluids) implementing linear types. See the docs for more.

No runtime deps