From 2cf6436fb1e3e130fa82cf89fabc91b81836d4c0 Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Fri, 1 Oct 2021 19:11:09 -0600 Subject: [PATCH] implement `borrowed_or` Allow the usage of `or` without consuming self. This can be useful for pipelines that maintain some sort of owned state. --- saphyr/src/yaml.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/saphyr/src/yaml.rs b/saphyr/src/yaml.rs index a6dc1f0..328775d 100644 --- a/saphyr/src/yaml.rs +++ b/saphyr/src/yaml.rs @@ -400,6 +400,16 @@ impl Yaml { this => this, } } + + /// See `or` for behavior. This performs the same operations, but with + /// borrowed values for less linear pipelines. + #[must_use] + pub fn borrowed_or<'a>(&'a self, other: &'a Self) -> &'a Self { + match self { + Yaml::BadValue | Yaml::Null => other, + this => this, + } + } } #[cfg_attr(feature = "cargo-clippy", allow(clippy::should_implement_trait))]