blob: 750904a0136403428e52c25992a9a46722f2d188 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
use std::borrow::Cow;
pub struct DropBomb {
msg: Cow<'static, str>,
defused: bool,
}
impl DropBomb {
pub fn new(msg: impl Into<Cow<'static, str>>) -> DropBomb {
DropBomb { msg: msg.into(), defused: false }
}
pub fn defuse(&mut self) { self.defused = true }
}
impl Drop for DropBomb {
fn drop(&mut self) {
if !self.defused && !::std::thread::panicking() {
panic!("{}", self.msg)
}
}
}
|