#stack-allocated #copy #array #fixed #no-alloc #contiguous #capacity

no-std copyvec

A contiguous growable array type, with a fixed, stack-alllocated capacity that implements Copy

7 releases

0.2.1 Sep 5, 2024
0.2.0 Jul 13, 2024
0.1.5 Jul 12, 2024

#633 in Rust patterns

Download history 325/week @ 2024-08-03 458/week @ 2024-08-10 759/week @ 2024-08-17 547/week @ 2024-08-24 976/week @ 2024-08-31 669/week @ 2024-09-07 541/week @ 2024-09-14 662/week @ 2024-09-21 689/week @ 2024-09-28 390/week @ 2024-10-05 280/week @ 2024-10-12 144/week @ 2024-10-19 344/week @ 2024-10-26 411/week @ 2024-11-02 230/week @ 2024-11-09 192/week @ 2024-11-16

1,196 downloads per month

MIT/Apache

49KB
865 lines

A stack-allocated sequence that mirror's Vec's API, but:

  • Implements Copy (and can only hold Copy types).
  • Does not grow.
  • Is #[no_std]/no-alloc compatible.

// const-friendly
const VEC: CopyVec<&str, 10> = CopyVec::new();

// easy initialising
let mut vec = copyvec!["a", "b", "c"; + 2];
                                   // ^~ with excess capacity

// use the API's you know
vec.push("d");

// including iteration
for it in &mut vec {
    if *it == "a" {
        *it = "A"
    }
}

assert_eq!(vec, ["A", "b", "c", "d"]);
vec.retain(|it| *it == "b" || *it == "c");
assert_eq!(vec.remove(0), "b");

Other features

If you like this crate, you may also enjoy stackstack


lib.rs:

A stack-allocated sequence that mirror's Vec's API, but:

  • Implements Copy (and can only hold Copy types).
  • Does not grow.
  • Is #[no_std]/no-alloc compatible.

// const-friendly
const VEC: CopyVec<&str, 10> = CopyVec::new();

// easy initialising
let mut vec = copyvec!["a", "b", "c"; + 2];
                                   // ^~ with excess capacity

// use the API's you know
vec.push("d");

// including iteration
for it in &mut vec {
    if *it == "a" {
        *it = "A"
    }
}

assert_eq!(vec, ["A", "b", "c", "d"]);
vec.retain(|it| *it == "b" || *it == "c");
assert_eq!(vec.remove(0), "b");

Other features

If you like this crate, you may also enjoy stackstack

Dependencies

~0–350KB