chiark / gitweb /
get_or_try_insert_with, but actually we're not going to use it
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 5 Dec 2020 11:12:26 +0000 (11:12 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 5 Dec 2020 11:17:52 +0000 (11:17 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/utils.rs

index 26196c2f3beb5bf70f7f76de9e95bd268fdea92a..3e8ceb841e6df868dcd688cfcc734a298ccbc412 100644 (file)
@@ -32,6 +32,29 @@ impl SplitAtDelim<char> for str {
   }
 }
 
+/*
+put trait OptionExt {
+  type Output;
+  fn get_or_try_insert_with<
+      E: Error,
+      F: FnOnce() -> Result<Output,E>,
+    >(&mut self, f: F) -> Result<&mut Output, E>;
+}
+
+impl<T> OptionExt for Option<T> {
+  type Output = T;
+  fn get_or_try_insert_with<E,F>
+    (&mut self, f: F) -> Result<&mut Output, E>
+    where E: Error, F: FnOnce() -> Result<Output,E>,
+  {
+    if self.is_none() {
+      *self = Some(f()?);
+    }
+    Ok(self.as_mut().unwrap())
+  }
+}
+*/
+
 // https://github.com/rust-lang/rust/issues/32255 :-(
 
 pub trait LocalFileExt {