From 7b4422bb5d3211128116ab484d3e5ff652d8fb0b 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. --- parser/src/yaml.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parser/src/yaml.rs b/parser/src/yaml.rs index a6dc1f0..328775d 100644 --- a/parser/src/yaml.rs +++ b/parser/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))]