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

temporary-annex

Helper for creating temporary annex on a collection

1 unstable release

0.1.0 Jan 11, 2022

#1373 in Data structures

Download history 54/week @ 2024-03-14 52/week @ 2024-03-21 57/week @ 2024-03-28 46/week @ 2024-04-04 37/week @ 2024-04-11 37/week @ 2024-04-18 29/week @ 2024-04-25 23/week @ 2024-05-02 27/week @ 2024-05-09 34/week @ 2024-05-16 31/week @ 2024-05-23 49/week @ 2024-05-30 27/week @ 2024-06-06 32/week @ 2024-06-13 35/week @ 2024-06-20 10/week @ 2024-06-27

109 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