This crate offers a MaybeOwned
trait which allows you to pass either an owned
or a borrowed value to a function. As opposed to [std::borrow::Cow
]
and [beef::Cow
], this trait
Cow
s;However, it also creates additional mental overhead and in case cases might cause genericity-induced problems.
Eventually, definition sites might become cleaner with an attribute proc macro.
```rust,norun use rand::Rng; use maybeowned_trait::MaybeOwned; use std::path::{Path, PathBuf};
// Definition site is a bit more verbose than with Cow
, yet still reasonable
fn myfn(path: impl for<'a> MaybeOwned
let path = PathBuf::from("hello"); // Call sites are clean myfn(&path); myfn(path); ```
With beef
[feature] enabled, this crate also provides the implementations of MaybeOwned
for [beef::Cow
] and [beef::lean::Cow
].