diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
commit | a0aa2307322cd47bbf416810ac0292925e03be87 (patch) | |
tree | 37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/generic-array/README.md | |
parent | Initial commit. (diff) | |
download | suricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip |
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/generic-array/README.md')
-rw-r--r-- | rust/vendor/generic-array/README.md | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/rust/vendor/generic-array/README.md b/rust/vendor/generic-array/README.md new file mode 100644 index 0000000..cf54f40 --- /dev/null +++ b/rust/vendor/generic-array/README.md @@ -0,0 +1,62 @@ +[](https://crates.io/crates/generic-array)
+[](https://travis-ci.org/fizyk20/generic-array)
+# generic-array
+
+This crate implements generic array types for Rust.
+
+**Requires minumum Rust version of 1.36.0, or 1.41.0 for `From<[T; N]>` implementations**
+
+[Documentation](http://fizyk20.github.io/generic-array/generic_array/)
+
+## Usage
+
+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:
+
+```rust
+struct Foo<N> {
+ data: [i32; N]
+}
+```
+
+**generic-array** defines a new trait `ArrayLength<T>` and a struct `GenericArray<T, N: ArrayLength<T>>`, which let the above be implemented as:
+
+```rust
+struct Foo<N: ArrayLength<i32>> {
+ data: GenericArray<i32, N>
+}
+```
+
+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:
+
+```rust
+use generic_array::typenum::U5;
+
+struct Foo<N: ArrayLength<i32>> {
+ data: GenericArray<i32, N>
+}
+
+fn main() {
+ let foo = Foo::<U5>{data: GenericArray::default()};
+}
+```
+
+For example, `GenericArray<T, U5>` would work almost like `[T; 5]`:
+
+```rust
+use generic_array::typenum::U5;
+
+struct Foo<T, N: ArrayLength<T>> {
+ data: GenericArray<T, N>
+}
+
+fn main() {
+ let foo = Foo::<i32, U5>{data: GenericArray::default()};
+}
+```
+
+In version 0.1.1 an `arr!` macro was introduced, allowing for creation of arrays as shown below:
+
+```rust
+let array = arr![u32; 1, 2, 3];
+assert_eq!(array[2], 3);
+```
|