try-push

Crates.iotry-push
lib.rstry-push
version1.0.2
sourcesrc
created_at2021-03-05 19:02:14.255366
updated_at2021-03-05 19:39:18.525099
descriptionA trait for attempting potentially expensive actions
homepage
repositoryhttps://github.com/nokel81/try-push/
max_upload_size
id364480
size5,026
Sebastian Malton (Nokel81)

documentation

README

This crate is useful for preventing expensive actions from taking place while adding elements to collections. It exports a single trait, TryPush and has implementations for both Vec<T> and VecDeque<T> from the standard library.

Examples:

use try_push::*;

let mut vec = Vec::with_capacity(4);
vec.push(1);
vec.push(2);
vec.push(3);
vec.push(4); // won't reallocate
// vec.push(5); // will reallocate

assert_eq!(vec.try_push(5), Element::NotAdded(5));
Commit count: 7

cargo fmt