#array #const #generics #arrays

newtype_array

A macro to help implementing the standard derived traits on newtype arrays

7 releases

0.1.6 Dec 7, 2018
0.1.5 Dec 7, 2018
0.1.4 Jul 6, 2018

#194 in Rust patterns

Download history 177/week @ 2019-12-10 3/week @ 2019-12-17 7/week @ 2019-12-24 105/week @ 2020-01-07 42/week @ 2020-01-14 6/week @ 2020-01-28 8/week @ 2020-02-04 10/week @ 2020-02-11 18/week @ 2020-02-18 14/week @ 2020-02-25 15/week @ 2020-03-03 42/week @ 2020-03-17 31/week @ 2020-03-24

103 downloads per month
Used in 2 crates

Apache-2.0/MIT

13KB
244 lines

This crate has a single macro, newtype_arrays, that will create transparent newtypes for arrays, and implement standard traits for them. It will be redundant when generic cosntants land, in the mean time it means you can use large arrays on stable rust.

Examples

#[macro_use]
extern crate newtype_array;

use std::collections::HashMap;

// Sha385 length
newtype_array!(pub struct Array48(pub 48));
// Sha512 length
newtype_array!(pub struct Array64(pub 64));

// We've got `Clone` and `PartialEq`/`Eq`
let arr1 = Array48([0u8; 48]);
let arr2 = arr1.clone();
assert_eq!(arr1, arr2);

// `Hash` is implemented as well
let mut map = HashMap::new();
map.insert(arr1, "hello");

lib.rs:

newtype_array

This crate has a single macro, newtype_arrays, that will create transparent newtypes for arrays, and implement standard traits for them. It will be redundant when generic cosntants land, in the mean time it means you can use large arrays on stable rust.

Examples

#[macro_use]
extern crate newtype_array;

use std::collections::HashMap;

# fn main() {
// Sha385 length
newtype_array!(pub struct Array48(pub 48));
// Sha512 length
newtype_array!(pub struct Array64(pub 64));

// We've got `Clone` and `PartialEq`/`Eq`
let arr1 = Array48([0u8; 48]);
let arr2 = arr1.clone();
assert_eq!(arr1, arr2);

// `Hash` is implemented as well
let mut map = HashMap::new();
map.insert(arr1, "hello");
# }

No runtime deps