diff options
| author | kennytm <kennytm@gmail.com> | 2018-09-14 14:50:09 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-14 14:50:09 +0800 |
| commit | b3303edba67981ed087fc89c4302985d022589d0 (patch) | |
| tree | 42e5a9a6e2bdd856601f42c0b6e1d859ec689ed6 /src/libcore/option.rs | |
| parent | 6ff0b2ed163dab4389d88b14b5729514c11c682e (diff) | |
| parent | a7a0225a281bbb9306862e647aee2f51aa595086 (diff) | |
| download | rust-b3303edba67981ed087fc89c4302985d022589d0.tar.gz rust-b3303edba67981ed087fc89c4302985d022589d0.zip | |
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)
Diffstat (limited to 'src/libcore/option.rs')
| -rw-r--r-- | src/libcore/option.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 53cf626bb1c..dfdc375765d 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -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 ///////////////////////////////////////////////////////////////////////////// |
