mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 21:16:27 +03:00
test arrray try_from (interesting const generic usage)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::convert::TryFrom;
|
||||
|
||||
fn empty_array() -> [u16; 0] {
|
||||
[]
|
||||
}
|
||||
@@ -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];
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user