initial
This commit is contained in:
commit
7c9bd9c81a
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "maybe_owned"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
22
src/lib.rs
Normal file
22
src/lib.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
pub enum MaybeOwned<'a, T: 'a> {
|
||||
Owned(T),
|
||||
Borrowed(&'a T),
|
||||
}
|
||||
|
||||
impl<'a, T: 'a> From<T> for MaybeOwned<'a, T> {
|
||||
fn from(value: T) -> Self {
|
||||
Self::Owned(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a> From<&'a T> for MaybeOwned<'a, T> {
|
||||
fn from(value: &'a T) -> Self {
|
||||
Self::Borrowed(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a + Default> Default for MaybeOwned<'a, T> {
|
||||
fn default() -> Self {
|
||||
MaybeOwned::Owned(T::default())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue