Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / third_party / rust / generic-array / README.md
blobcf54f405509f0a9dd89dbdb7e4eba69cf3f93d2c
1 [![Crates.io](https://img.shields.io/crates/v/generic-array.svg)](https://crates.io/crates/generic-array)\r
2 [![Build Status](https://travis-ci.org/fizyk20/generic-array.svg?branch=master)](https://travis-ci.org/fizyk20/generic-array)\r
3 # generic-array\r
4 \r
5 This crate implements generic array types for Rust.\r
6 \r
7 **Requires minumum Rust version of 1.36.0, or 1.41.0 for `From<[T; N]>` implementations**\r
8 \r
9 [Documentation](http://fizyk20.github.io/generic-array/generic_array/)\r
11 ## Usage\r
13 The Rust arrays `[T; N]` are problematic in that they can't be used generically with respect to `N`, so for example this won't work:\r
15 ```rust\r
16 struct Foo<N> {\r
17         data: [i32; N]\r
18 }\r
19 ```\r
21 **generic-array** defines a new trait `ArrayLength<T>` and a struct `GenericArray<T, N: ArrayLength<T>>`, which let the above be implemented as:\r
23 ```rust\r
24 struct Foo<N: ArrayLength<i32>> {\r
25         data: GenericArray<i32, N>\r
26 }\r
27 ```\r
29 The `ArrayLength<T>` trait is implemented by default for [unsigned integer types](http://fizyk20.github.io/generic-array/typenum/uint/index.html) from [typenum](http://fizyk20.github.io/generic-array/typenum/index.html) crate:\r
31 ```rust\r
32 use generic_array::typenum::U5;\r
34 struct Foo<N: ArrayLength<i32>> {\r
35     data: GenericArray<i32, N>\r
36 }\r
38 fn main() {\r
39     let foo = Foo::<U5>{data: GenericArray::default()};\r
40 }\r
41 ```\r
43 For example, `GenericArray<T, U5>` would work almost like `[T; 5]`:\r
45 ```rust\r
46 use generic_array::typenum::U5;\r
48 struct Foo<T, N: ArrayLength<T>> {\r
49     data: GenericArray<T, N>\r
50 }\r
52 fn main() {\r
53     let foo = Foo::<i32, U5>{data: GenericArray::default()};\r
54 }\r
55 ```\r
57 In version 0.1.1 an `arr!` macro was introduced, allowing for creation of arrays as shown below:\r
59 ```rust\r
60 let array = arr![u32; 1, 2, 3];\r
61 assert_eq!(array[2], 3);\r
62 ```\r