#annex #temporary #collection #cleanup #once #scope #vec

temporary-annex

Helper for creating temporary annex on a collection

1 unstable release

0.1.0 Jan 11, 2022

#1481 in Data structures

Download history 23/week @ 2024-11-13 11/week @ 2024-11-20 65/week @ 2024-11-27 22/week @ 2024-12-04 29/week @ 2024-12-11 6/week @ 2024-12-18 3/week @ 2024-12-25 13/week @ 2025-01-01 7/week @ 2025-01-08 10/week @ 2025-01-15 8/week @ 2025-01-22 8/week @ 2025-01-29 100/week @ 2025-02-05 43/week @ 2025-02-12 77/week @ 2025-02-19 34/week @ 2025-02-26

255 downloads per month
Used in 4 crates (2 directly)

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