#semver #string-key #hash-map #store

semver-store

An HashMap structure that uses semver strings as keys

2 unstable releases

0.2.0 Sep 10, 2019
0.1.0 Sep 3, 2019

#1919 in Data structures

MIT license

19KB
369 lines

semver-store

Crates.io Crates.io

An HashMap structure that uses semver strings as keys.

Install

cargo add semver-store

API

insert

Add a value to the store for a given version.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());

contains_key

Checks if a key has been inserted.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());
assert_eq!(store.contains_key(&"1.0.0".to_string()), true);

get

Get the reference fo a stored value.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());
assert_eq!(store.get(&"1.0.0".to_string()).unwrap(), &"hello");

Wildcards are supported! If you use a wildcard you will always get the maximum version for a give major/minor.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());
store.insert(&"1.1.0".to_string(), "world!".to_string());
assert_eq!(store.get(&"1.x".to_string()).unwrap(), &"world");

store.insert(&"2.1.1".to_string(), "hello!".to_string());
store.insert(&"2.1.2".to_string(), "world!".to_string());
assert_eq!(store.get(&"2.1.x".to_string()).unwrap(), &"world");
assert_eq!(store.get(&"2.1".to_string()).unwrap(), &"world");

remove

Removes a given version from the store.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());
assert_eq!(store.get(&"1.0.0".to_string()).unwrap(), &"hello");

store.remove(&"1.0.0".to_string());
assert_eq!(store.get(&"1.0.0".to_string()), None);

Wildcards are supported! If you use a wildcard you will always delete the maximum version for a give major/minor.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());
store.insert(&"1.1.0".to_string(), "hello!".to_string());
assert_eq!(store.get(&"1.0.0".to_string()).unwrap(), &"hello");

store.remove(&"1.x".to_string());
assert_eq!(store.get(&"1.0.0".to_string()).unwrap(), &"hello");
assert_eq!(store.get(&"1.1.0".to_string()), None);

empty

Empties the store.

let mut store = SemverStore::<String>::new();
store.insert(&"1.0.0".to_string(), "hello!".to_string());
assert_eq!(store.get(&"1.0.0".to_string()).unwrap(), &"hello");

store.empty();
assert_eq!(store.get(&"1.0.0".to_string()), None);

License

MIT

No runtime deps