Rollup merge of #53218 - weiznich:feature/option_ref_into, r=KodrAus

Add a implementation of `From` for converting `&'a Option<T>` into `Option<&'a T>`

I'm not sure if any annotations regarding the stabilization are needed or in general what's the correct process of adding such an impl.

cc @sgrif (We have talked about this)
This commit is contained in:
kennytm 2018-09-14 14:50:09 +08:00 committed by GitHub
commit b3303edba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1062,6 +1062,20 @@ impl<T> From<T> for Option<T> {
}
}
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
fn from(o: &'a Option<T>) -> Option<&'a T> {
o.as_ref()
}
}
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
fn from(o: &'a mut Option<T>) -> Option<&'a mut T> {
o.as_mut()
}
}
/////////////////////////////////////////////////////////////////////////////
// The Option Iterators
/////////////////////////////////////////////////////////////////////////////