File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -2096,6 +2096,22 @@ impl<T> From<T> for Option<T> {
2096
2096
}
2097
2097
}
2098
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
+
2099
2115
#[ stable( feature = "option_ref_from_ref_option" , since = "1.30.0" ) ]
2100
2116
impl < ' a , T > From < & ' a Option < T > > for Option < & ' a T > {
2101
2117
/// Converts from `&Option<T>` to `Option<&T>`.
You can’t perform that action at this time.
0 commit comments