| Crates.io | arrayy |
| lib.rs | arrayy |
| version | 0.1.2 |
| created_at | 2024-12-26 14:53:55.692891+00 |
| updated_at | 2024-12-28 12:45:43.250936+00 |
| description | Stack-allocated fixed-size array with useful methods on top of Rust's [T; L] type. |
| homepage | |
| repository | https://github.com/ManiGhazaee/arrayy |
| max_upload_size | |
| id | 1495683 |
| size | 32,449 |
Stack-allocated fixed-size array with useful methods on top of Rust's [T; L] type.
newlenset_lenset_len_uncheckedbufbuf_mutcapacityis_emptygetget_mutget_uncheckedget_unchecked_mutlastlast_mutfirstfirst_mutfrompushpush_uncheckedpoppop_uncheckediteriter_mutinto_iterappendappend_sliceappend_uncheckedappend_slice_uncheckedfiltermaptruncateas_sliceas_mut_sliceas_vecinsertinsert_uncheckedremoveremove_uncheckedclearas_mut_ptras_ptras_mut_ptr_rangeas_ptr_rangeuse arrayy::{array, Array};
let a = array![u8; 10]; // empty array (len = 0) with capacity = 10
// same as
let a: Array<u8, 10> = Array::default();
let b = array![1u8, 2, 3; 10]; // array with 3 elements (len = 3) and capacity = 10
// same as
let b = Array::<u8, 10>::from(&[1, 2, 3]);
let c = array![1u8, 2, 3]; // array with 3 elements (len = 3) and capacity = 3
// same as
let c = Array::<u8, 3>::from(&[1, 2, 3]);
let mut arr = array![1, 2, 3; 10];
arr.push(4);
assert_eq!(arr.len(), 4);
assert_eq!(arr.pop(), Some(4));
assert_eq!(arr.len(), 3);
let arr = array![1, 2, 3];
assert_eq!(arr[1], 2);
assert_eq!(arr.get(1), Some(&2));
assert_eq!(arr.first(), Some(&1));
assert_eq!(arr.last(), Some(&3));
let arr = array![1, 2, 3];
for val in arr.iter() {
println!("{}", val);
}
let mut arr = array![1, 2, 3];
for val in arr.iter_mut() {
*val *= 2;
}
assert_eq!(arr, array![2, 4, 6]);
let arr = array![1, 2, 3, 4, 5];
let filtered = arr.filter(|&x| x % 2 == 0);
assert_eq!(filtered, array![2, 4]);
let mapped = arr.map(|&x| x * 2);
assert_eq!(mapped, array![2, 4, 6, 8, 10]);
let mut arr1 = array![1, 2, 3; 5];
let arr2 = array![4, 5];
arr1.append(&arr2);
assert_eq!(arr1, array![1, 2, 3, 4, 5]);