From 79d1684cd33e329d8cf7919af3c1d86e4b8c02dc Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 17 May 2024 10:42:12 -0700 Subject: [PATCH] Add test of ensure through a Not impl --- tests/test_macros.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_macros.rs b/tests/test_macros.rs index 10740a9..55e0fc9 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -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() { @@ -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(()) }