~ioiojo/optional-collections

Traits for working with Option-wrapped collections
update license year to 2023
Vec::new() not with_capacity()

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~ioiojo/optional-collections
read/write
git@git.sr.ht:~ioiojo/optional-collections

You can also use your local clone with git send-email.

#optional-collections

Traits for working with Option-wrapped collections.

#Synopsis

use optional_collections::{InsertOrInit, PushOrInit};
use std::collections::HashMap;

fn main() {
    let mut map: Option<HashMap<&'static str, bool>> = None;
    map.insert_or_init("a", true);
    map.insert_or_init("b", false);
    map.insert_or_init("c", true);
    let map = map.unwrap();
    assert_eq!(map.get("a").unwrap(), &true);
    assert_eq!(map.get("b").unwrap(), &false);
    assert_eq!(map.get("c").unwrap(), &true);

    let mut vec: Option<Vec<&'static str>> = None;
    vec.push_or_init("a");
    vec.push_or_init("b");
    vec.push_or_init("c");
    let vec = vec.unwrap();
    assert_eq!(vec[0], "a");
    assert_eq!(vec[1], "b");
    assert_eq!(vec[2], "c");
}

#License

Licensed under either of

at your option.

#Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Do not follow this link