implement borrowed_or

Allow the usage of `or` without consuming self. This can be useful
for pipelines that maintain some sort of owned state.
This commit is contained in:
lincoln auster [they/them] 2021-10-01 19:11:09 -06:00 committed by Ethiraric
parent 5ba5dfa6e6
commit 2cf6436fb1

View file

@ -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))]