Debian Codegraph @

.cargo/vendor/anyhow/tests/ui/ensure-nonbool.rs

raw
1 use anyhow::{ensure, Result};
2 use std::ops::{Deref, Not};
3
4 struct Bool(bool);
5
6 struct DerefBool(bool);
7
8 struct NotBool(bool);
9
10 impl Deref for DerefBool {
11 type Target = bool;
12 fn deref(&self) -> &Self::Target {
13 &self.0
14 }
15 }
16
17 impl Not for NotBool {
18 type Output = bool;
19 fn not(self) -> Self::Output {
20 !self.0
21 }
22 }
23
24 fn main() -> Result<()> {
25 ensure!("...");
26
27 let mut s = Bool(true);
28 match &mut s {
29 Bool(cond) => ensure!(cond),
30 }
31
32 let db = DerefBool(true);
33 ensure!(db);
34 ensure!(&db);
35
36 let nb = NotBool(true);
37 ensure!(nb);
38
39 Ok(())
40 }