added more functions from original code, added macro

This commit is contained in:
Vlasislav Kashin
2025-07-02 18:02:47 +03:00
parent 929fdbae8a
commit d0fb47705a
14 changed files with 1177 additions and 41 deletions

21
src/macros/mod.rs Normal file
View File

@@ -0,0 +1,21 @@
// std::borrow::Cow
// std::option::Option
/// This macro extracts owned value from cow
/// but if cow is borrowed it returns default given value
///
/// it's helpful when function returns `Cow<'_, T>` as result,
/// where `Cow::Borrowed` option marks that value was not modified
/// and we can use owned original instead of copying it.
macro_rules! owned_from_cow_or {
($getcow:expr, $default:expr) => {{
if let std::borrow::Cow::Owned(s) = $getcow {
s
} else {
$default
}
}};
}
pub(crate) use owned_from_cow_or;