[−][src]Crate mown
This crate provides two simple wrappers
Mown
and
MownMut
for values that can be either owned or borrowed.
The type Mown
is an simple enum
type with two constructors:
pub enum Mown<'a, T> { Owned(T), Borrowed(&'a T) }
The mutable version MownMut
follows the same definition with a mutable
reference.
This is very similar to the standard
Cow
type, except that it is not possible to transform a borrowed value into an owned
one.
Basic Usage
One basic use case for the Mown
type is the situation where one wants to
reuse some input borrowed value under some condition, or then use a custom
owned value.
use mown::Mown; fn function(input_value: &T) { let value = if condition { Mown::Borrowed(input_value) } else { let custom_value: T = init_custom_value ; Mown::Owned(custom_value) }; // do something with `value`. }
Enums
Mown | Container for borrowed or owned value. |
MownMut | Container for mutabily borrowed or owned values. |