#temporary #vec #cleanup #scope #helper #once #type #result #collections

temporary-annex

Helper for creating temporary annex on a collection

1 unstable release

0.1.0 Jan 11, 2022
Download history 1/week @ 2022-12-01 2/week @ 2022-12-08 1/week @ 2022-12-15 1/week @ 2022-12-29 1/week @ 2023-01-05 1/week @ 2023-01-19 5/week @ 2023-01-26 4/week @ 2023-02-02 7/week @ 2023-02-09 5/week @ 2023-02-16 33/week @ 2023-02-23 61/week @ 2023-03-02 32/week @ 2023-03-09 100/week @ 2023-03-16

227 downloads per month
Used in 3 crates (via ezno-parser)

MIT license

4KB
57 lines

Temporary Annex

Allows pushing to a Vec (or any other type implementing Annexable) with cleanup once result goes out of scope.

e.g.

let mut vec1 = vec![1, 2, 3];
assert_eq!(vec1, [1, 2, 3]);
{
    let new_vec_ref = vec1.push_annex(4);
    assert_eq!(*new_vec_ref, [1, 2, 3, 4]);
}
assert_eq!(vec1, [1, 2, 3]);

This has the effect of a immutable structure but uses the same underlying allocation (no cloning or additional allocations).

No runtime deps