Either an owned or borrowed value, with type known at compile time

Crates.io Downloads Documentation License Dependency Status

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

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.

Simple example

```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 = &'a Path>) { // Of course, you'll have a meaningful condition here if rand::threadrng().gen::() { let pathbuf: PathBuf = path.toowned(); println!("Owned buf: {:?}", path_buf); } else { let path: &Path = path.borrow(); println!("Borrowed path: {:?}", path); }; }

let path = PathBuf::from("hello"); // Call sites are clean myfn(&path); myfn(path); ```