#temporary #goes #cleanup #annex #collection #scope #vec

temporary-annex

Helper for creating temporary annex on a collection

1 unstable release

0.1.0 Jan 11, 2022

#1450 in Data structures

Download history 28/week @ 2024-07-22 47/week @ 2024-07-29 118/week @ 2024-08-05 47/week @ 2024-08-12 30/week @ 2024-08-19 69/week @ 2024-08-26 91/week @ 2024-09-02 23/week @ 2024-09-09 14/week @ 2024-09-16 37/week @ 2024-09-23 32/week @ 2024-09-30 100/week @ 2024-10-07 19/week @ 2024-10-14 7/week @ 2024-10-21 6/week @ 2024-10-28 16/week @ 2024-11-04

124 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