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

temporary-annex

Helper for creating temporary annex on a collection

1 unstable release

0.1.0 Jan 11, 2022

#1233 in Data structures

Download history 267/week @ 2024-01-04 171/week @ 2024-01-11 46/week @ 2024-01-18 27/week @ 2024-01-25 24/week @ 2024-02-01 39/week @ 2024-02-08 46/week @ 2024-02-15 57/week @ 2024-02-22 61/week @ 2024-02-29 53/week @ 2024-03-07 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 25/week @ 2024-04-18

168 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