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:
parent
f8542f0f97
commit
7b4422bb5d
1 changed files with 10 additions and 0 deletions
|
@ -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))]
|
||||
|
|
Loading…
Reference in a new issue