ensure-nonbool.rs
This file
Path
tests/ui/ensure-nonbool.rs
40 lines · 612 bytes · Rust
Last changed by
Merge pull request #367 from dtolnay/notboolDavid Tolnaybefore adoption20a9ff7
History of this fileTake it
1use anyhow::{ensure, Result};2use std::ops::{Deref, Not};34struct Bool(bool);56struct DerefBool(bool);78struct NotBool(bool);910impl Deref for DerefBool {11 type Target = bool;12 fn deref(&self) -> &Self::Target {13 &self.014 }15}1617impl Not for NotBool {18 type Output = bool;19 fn not(self) -> Self::Output {20 !self.021 }22}2324fn main() -> Result<()> {25 ensure!("...");2627 let mut s = Bool(true);28 match &mut s {29 Bool(cond) => ensure!(cond),30 }3132 let db = DerefBool(true);33 ensure!(db);34 ensure!(&db);3536 let nb = NotBool(true);37 ensure!(nb);3839 Ok(())40}