Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test arrray try_from (interesting const generic usage) #837

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ef1ecbefb8719e408150738664d443a73f757ffd
14890954ce17c44d944eda988c5a64bb4c5ec9eb
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();
}