Skip to content

Commit b3303ed

Browse files
authored
Rollup merge of rust-lang#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)
2 parents 6ff0b2e + a7a0225 commit b3303ed

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: src/libcore/option.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,20 @@ impl<T> From<T> for Option<T> {
10621062
}
10631063
}
10641064

1065+
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
1066+
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
1067+
fn from(o: &'a Option<T>) -> Option<&'a T> {
1068+
o.as_ref()
1069+
}
1070+
}
1071+
1072+
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
1073+
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
1074+
fn from(o: &'a mut Option<T>) -> Option<&'a mut T> {
1075+
o.as_mut()
1076+
}
1077+
}
1078+
10651079
/////////////////////////////////////////////////////////////////////////////
10661080
// The Option Iterators
10671081
/////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)