Skip to content

Commit

Permalink
test arrray try_from (interesting const generic usage)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 13, 2019
1 parent f1b623c commit ed2ff69
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/run-pass/arrays.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::convert::TryFrom;

fn empty_array() -> [u16; 0] {
[]
}
Expand Down Expand Up @@ -33,6 +35,16 @@ fn slice_index() -> u8 {
arr[5]
}

fn try_from() {
const N: usize = 16;
type Array = [u8; N];
let array: Array = [0; N];
let slice: &[u8] = &array[..];

let result = <&Array>::try_from(slice);
assert_eq!(&array, result.unwrap());
}

fn eq() {
const N: usize = 16;
type Array = [u8; N];
Expand All @@ -57,6 +69,7 @@ fn main() {
assert_eq!(array_array(), [[5, 4], [3, 2], [1, 0]]);
assert_eq!(array_repeat(), [42; 8]);
assert_eq!(mini_array(), [42]);
try_from();
eq();
debug();
}

0 comments on commit ed2ff69

Please sign in to comment.