| Crates.io | array-plus-extra |
| lib.rs | array-plus-extra |
| version | 0.3.0 |
| created_at | 2025-11-16 09:54:40.694237+00 |
| updated_at | 2025-11-16 20:16:09.951685+00 |
| description | An array type that holds N+EXTRA elements with const generic parameters, providing safe slice access to contiguous memory |
| homepage | https://github.com/korken89/array-plus-extra |
| repository | https://github.com/korken89/array-plus-extra |
| max_upload_size | |
| id | 1935372 |
| size | 48,306 |
An array type that holds N+EXTRA elements using const generic parameters, providing safe slice access to contiguous memory.
This allows the creation of arrays that would require more powerful const-generics, e.g. [T; N+3].
&{mut} [T] provides safe access to all N+EXTRA elementsuse array_plus_extra::ArrayPlusExtra;
// Create an array with 5 base elements + 3 extra = 8 total elements.
let arr: ArrayPlusExtra<i32, 5, 3> = ArrayPlusExtra::new(42);
// Access via deref to slice.
assert_eq!(arr.len(), 8);
assert_eq!(arr[0], 42);
assert_eq!(arr[7], 42);
// Use slice methods.
let sum: i32 = arr.iter().sum();
assert_eq!(sum, 336); // 42 * 8
use array_plus_extra::ArrayPlusExtra;
let mut arr: ArrayPlusExtra<i32, 2, 2> = ArrayPlusExtra::new(0);
// Modify through deref_mut.
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
assert_eq!(arr[0], 10);
assert_eq!(arr[3], 40);
use array_plus_extra::ArrayPlusExtra;
const ARR: ArrayPlusExtra<u8, 3, 2> = ArrayPlusExtra::new(255);
const SLICE: &[u8] = ARR.as_slice();
const LEN: usize = SLICE.len();
assert_eq!(LEN, 5);
assert_eq!(SLICE[0], 255);
Run tests:
cargo test
Run tests with Miri (requires nightly):
cargo +nightly miri test
This crate requires Rust 1.85 or later due to the use of Edition 2024 and const fn features.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.