From f47599c549086487385760a89e9cc7cffeead11e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 5 Dec 2020 11:12:26 +0000 Subject: [PATCH] get_or_try_insert_with, but actually we're not going to use it Signed-off-by: Ian Jackson --- src/utils.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index 26196c2f..3e8ceb84 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -32,6 +32,29 @@ impl SplitAtDelim for str { } } +/* +put trait OptionExt { + type Output; + fn get_or_try_insert_with< + E: Error, + F: FnOnce() -> Result, + >(&mut self, f: F) -> Result<&mut Output, E>; +} + +impl OptionExt for Option { + type Output = T; + fn get_or_try_insert_with + (&mut self, f: F) -> Result<&mut Output, E> + where E: Error, F: FnOnce() -> Result, + { + if self.is_none() { + *self = Some(f()?); + } + Ok(self.as_mut().unwrap()) + } +} +*/ + // https://github.com/rust-lang/rust/issues/32255 :-( pub trait LocalFileExt { -- 2.30.2