From: Ian Jackson Date: Sat, 5 Dec 2020 11:12:26 +0000 (+0000) Subject: get_or_try_insert_with, but actually we're not going to use it X-Git-Tag: otter-0.2.0~282 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f47599c549086487385760a89e9cc7cffeead11e;p=otter.git get_or_try_insert_with, but actually we're not going to use it Signed-off-by: Ian Jackson --- 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 {