From 41d54cd3905e21b16536e9fe73c714d1b887292c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 4 Apr 2021 20:23:18 +0100 Subject: [PATCH] apitest: Use #[ext] a bit more Signed-off-by: Ian Jackson --- apitest/apitest.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 1da3d538..a8ecaef4 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -255,26 +255,17 @@ macro_rules! test { // -------------------- Extra anyhow result handling -------------------- -pub trait AlwaysContext { - fn always_context(self, msg: &'static str) -> anyhow::Result; -} - -impl AlwaysContext for Result -where Self: anyhow::Context, -{ - fn always_context(self, msg: &'static str) -> anyhow::Result { +#[ext(pub)] +impl Result { + fn always_context(self, msg: &'static str) -> anyhow::Result + where Self: anyhow::Context + { let x = self.context(msg); if x.is_ok() { info!("completed {}.", msg) }; x } -} - -pub trait JustWarn { - fn just_warn(self) -> Option; -} -impl JustWarn for Result { - fn just_warn(self) -> Option { + fn just_warn(self) -> Option where E: Display { match self { Ok(x) => Some(x), Err(e) => { -- 2.30.2