arr.rs |
Implementation for `arr!` macro. |
3765 |
functional.rs |
Functional programming with generic sequences
Please see `tests/generics.rs` for examples of how to best use these in your generic functions. |
3448 |
hex.rs |
Generic array are commonly used as a return value for hash digests, so
it's a good idea to allow to hexlify them easily. This module implements
`std::fmt::LowerHex` and `std::fmt::UpperHex` traits.
Example:
```rust
# #[macro_use]
# extern crate generic_array;
# extern crate typenum;
# fn main() {
let array = arr![u8; 10, 20, 30];
assert_eq!(format!("{:x}", array), "0a141e");
# }
```
|
3761 |
impl_serde.rs |
Serde serialization/deserialization implementation |
2847 |
impl_zeroize.rs |
|
577 |
impls.rs |
|
6619 |
iter.rs |
`GenericArray` iterator implementation. |
6083 |
lib.rs |
This crate implements a structure that can be used as a generic array type.
Core Rust array types `[T; N]` can't be used generically with
respect to `N`, so for example this:
```rust{compile_fail}
struct Foo<T, N> {
data: [T; N]
}
```
won't work.
**generic-array** exports a `GenericArray<T,N>` type, which lets
the above be implemented as:
```rust
use generic_array::{ArrayLength, GenericArray};
struct Foo<T, N: ArrayLength<T>> {
data: GenericArray<T,N>
}
```
The `ArrayLength<T>` trait is implemented by default for
[unsigned integer types](../typenum/uint/index.html) from
[typenum](../typenum/index.html):
```rust
# use generic_array::{ArrayLength, GenericArray};
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::{ArrayLength, GenericArray};
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()};
# }
```
For ease of use, an `arr!` macro is provided - example below:
```
# #[macro_use]
# extern crate generic_array;
# extern crate typenum;
# fn main() {
let array = arr![u32; 1, 2, 3];
assert_eq!(array[2], 3);
# }
``` |
18699 |
sequence.rs |
Useful traits for manipulating sequences of data stored in `GenericArray`s |
11550 |