Skip to content

Commit ed2ff69

Browse files
committed
test arrray try_from (interesting const generic usage)
1 parent f1b623c commit ed2ff69

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/run-pass/arrays.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::convert::TryFrom;
2+
13
fn empty_array() -> [u16; 0] {
24
[]
35
}
@@ -33,6 +35,16 @@ fn slice_index() -> u8 {
3335
arr[5]
3436
}
3537

38+
fn try_from() {
39+
const N: usize = 16;
40+
type Array = [u8; N];
41+
let array: Array = [0; N];
42+
let slice: &[u8] = &array[..];
43+
44+
let result = <&Array>::try_from(slice);
45+
assert_eq!(&array, result.unwrap());
46+
}
47+
3648
fn eq() {
3749
const N: usize = 16;
3850
type Array = [u8; N];
@@ -57,6 +69,7 @@ fn main() {
5769
assert_eq!(array_array(), [[5, 4], [3, 2], [1, 0]]);
5870
assert_eq!(array_repeat(), [42; 8]);
5971
assert_eq!(mini_array(), [42]);
72+
try_from();
6073
eq();
6174
debug();
6275
}

0 commit comments

Comments
 (0)