We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fec98b3 commit b76dda0Copy full SHA for b76dda0
library/core/src/option.rs
@@ -2096,6 +2096,22 @@ impl<T> From<T> for Option<T> {
2096
}
2097
2098
2099
+impl<'a, T, const N: usize> From<&'a [T; N]> for Option<&'a [T]> {
2100
+ /// Converts a reference to an array into a reference to an array slice.
2101
+ ///
2102
+ /// # Examples
2103
2104
+ /// ```
2105
+ /// let array = [1, 2, 3];
2106
+ /// let option: Option<&[i32]> = Option::from(&array);
2107
2108
+ /// assert_eq!(option, Some(&[1, 2, 3][..]));
2109
2110
+ fn from(slice: &'a [T; N]) -> Option<&'a [T]> {
2111
+ Some(slice.as_slice())
2112
+ }
2113
+}
2114
+
2115
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
2116
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
2117
/// Converts from `&Option<T>` to `Option<&T>`.
0 commit comments