Created
April 18, 2017 14:31
-
-
Save qryxip/6f6616e773c73434b33658f746bffd25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::borrow::Cow; | |
trait FromRefOpt<'a, T> { | |
fn from_ref_opt(option: Option<&'a T>) -> Self; | |
} | |
impl<'a, T: Clone + Default> FromRefOpt<'a, T> for Cow<'a, T> { | |
fn from_ref_opt(option: Option<&'a T>) -> Cow<'a, T> { | |
if let Some(x) = option { | |
Cow::Borrowed(x) | |
} else { | |
Cow::Owned(T::default()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment