about summary refs log tree commit diff
path: root/tvix/eval/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/lib.rs')
-rw-r--r--tvix/eval/src/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index 6cf3aa212a18..00f680bc7a2e 100644
--- a/tvix/eval/src/lib.rs
+++ b/tvix/eval/src/lib.rs
@@ -22,6 +22,8 @@ mod test_utils;
 #[cfg(test)]
 mod tests;
 
+use std::rc::Rc;
+
 // Re-export the public interface used by other crates.
 pub use crate::builtins::global_builtins;
 pub use crate::compiler::{compile, prepare_globals};
@@ -31,3 +33,9 @@ pub use crate::pretty_ast::pretty_print_expr;
 pub use crate::source::SourceCode;
 pub use crate::value::Value;
 pub use crate::vm::run_lambda;
+
+// TODO: use Rc::unwrap_or_clone once it is stabilised.
+// https://doc.rust-lang.org/std/rc/struct.Rc.html#method.unwrap_or_clone
+pub fn unwrap_or_clone_rc<T: Clone>(rc: Rc<T>) -> T {
+    Rc::try_unwrap(rc).unwrap_or_else(|rc| (*rc).clone())
+}