about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-12-30 10:36:37 -0800
committerDavid Tolnay <dtolnay@gmail.com>2021-12-30 10:36:37 -0800
commit48a91a08d166d293fcc03fdc9f86fa30ecbcc51c (patch)
tree88b53c4379f58a4adced133a331e6029c45956de
parentbbcf09f2fb50c146a4b79a1cfece94bfbe1b159a (diff)
downloadrust-48a91a08d166d293fcc03fdc9f86fa30ecbcc51c.tar.gz
rust-48a91a08d166d293fcc03fdc9f86fa30ecbcc51c.zip
Move Option::as_deref
-rw-r--r--library/core/src/option.rs54
1 files changed, 26 insertions, 28 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index d457d502c25..8feebe11e97 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -1072,6 +1072,32 @@ impl<T> Option<T> {
         }
     }
 
+    /// Converts from `Option<T>` (or `&Option<T>`) to `Option<&T::Target>`.
+    ///
+    /// Leaves the original Option in-place, creating a new one with a reference
+    /// to the original one, additionally coercing the contents via [`Deref`].
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// let x: Option<String> = Some("hey".to_owned());
+    /// assert_eq!(x.as_deref(), Some("hey"));
+    ///
+    /// let x: Option<String> = None;
+    /// assert_eq!(x.as_deref(), None);
+    /// ```
+    #[stable(feature = "option_deref", since = "1.40.0")]
+    #[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
+    pub const fn as_deref(&self) -> Option<&T::Target>
+    where
+        T: ~const Deref,
+    {
+        match self.as_ref() {
+            Some(t) => Some(t.deref()),
+            None => None,
+        }
+    }
+
     /////////////////////////////////////////////////////////////////////////
     // Iterator constructors
     /////////////////////////////////////////////////////////////////////////
@@ -1724,34 +1750,6 @@ impl<T: Clone> Option<&mut T> {
     }
 }
 
-impl<T: Deref> Option<T> {
-    /// Converts from `Option<T>` (or `&Option<T>`) to `Option<&T::Target>`.
-    ///
-    /// Leaves the original Option in-place, creating a new one with a reference
-    /// to the original one, additionally coercing the contents via [`Deref`].
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// let x: Option<String> = Some("hey".to_owned());
-    /// assert_eq!(x.as_deref(), Some("hey"));
-    ///
-    /// let x: Option<String> = None;
-    /// assert_eq!(x.as_deref(), None);
-    /// ```
-    #[stable(feature = "option_deref", since = "1.40.0")]
-    #[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
-    pub const fn as_deref(&self) -> Option<&T::Target>
-    where
-        T: ~const Deref,
-    {
-        match self.as_ref() {
-            Some(t) => Some(t.deref()),
-            None => None,
-        }
-    }
-}
-
 impl<T: DerefMut> Option<T> {
     /// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
     ///