update license year to 2023
Vec::new() not with_capacity()
Traits for working with Option
-wrapped collections.
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");
}
Licensed under either of
at your option.
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.