Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/generic-array/README.md # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / generic-array / README.md` 62 lines ยท 1777 bytes Raw Blame History Rendered 1 [![Crates.io](https://img.shields.io/crates/v/generic-array.svg)](https://crates.io/crates/generic-array) 2 [![Build Status](https://travis-ci.org/fizyk20/generic-array.svg?branch=master)](https://travis-ci.org/fizyk20/generic-array) 3 # generic-array 4 5 This crate implements generic array types for Rust. 6 7 **Requires minumum Rust version of 1.36.0, or 1.41.0 for `From<[T; N]>` implementations** 8 9 [Documentation](http://fizyk20.github.io/generic-array/generic_array/) 10 11 ## Usage 12 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: 14 15 ```rust 16 struct Foo { 17 data: [i32; N] 18 } 19 ``` 20 21 **generic-array** defines a new trait `ArrayLength` and a struct `GenericArray>`, which let the above be implemented as: 22 23 ```rust 24 struct Foo> { 25 data: GenericArray 26 } 27 ``` 28 29 The `ArrayLength` 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: 30 31 ```rust 32 use generic_array::typenum::U5; 33 34 struct Foo> { 35 data: GenericArray 36 } 37 38 fn main() { 39 let foo = Foo::{data: GenericArray::default()}; 40 } 41 ``` 42 43 For example, `GenericArray` would work almost like `[T; 5]`: 44 45 ```rust 46 use generic_array::typenum::U5; 47 48 struct Foo> { 49 data: GenericArray 50 } 51 52 fn main() { 53 let foo = Foo::{data: GenericArray::default()}; 54 } 55 ``` 56 57 In version 0.1.1 an `arr!` macro was introduced, allowing for creation of arrays as shown below: 58 59 ```rust 60 let array = arr![u32; 1, 2, 3]; 61 assert_eq!(array[2], 3); 62 ```