Skip to content

Commit

Permalink
Add test of ensure through a Not impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 17, 2024
1 parent 2b42f62 commit 79d1684
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use self::common::*;
use anyhow::{anyhow, ensure, Result};
use std::cell::Cell;
use std::future;
use std::ops::Not;

#[test]
fn test_messages() {
Expand Down Expand Up @@ -60,11 +61,20 @@ fn test_ensure_nonbool() -> Result<()> {
condition: bool,
}

impl Not for Struct {
type Output = bool;
fn not(self) -> Self::Output {
!self.condition
}
}

let s = Struct { condition: true };
match &s {
Struct { condition } => ensure!(condition), // &bool
}

ensure!(s);

Ok(())
}

Expand Down

0 comments on commit 79d1684

Please sign in to comment.