semver-store

Crates.io Crates.io

An HashMap structure that uses semver strings as keys.

Install

sh cargo add semver-store

API

insert

Add a value to the store for a given version.

rust 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.

rust 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.

rust 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.

```rust let mut store = SemverStore::::new(); store.insert(&"1.0.0".tostring(), "hello!".tostring()); store.insert(&"1.1.0".tostring(), "world!".tostring()); asserteq!(store.get(&"1.x".tostring()).unwrap(), &"world");

store.insert(&"2.1.1".tostring(), "hello!".tostring()); store.insert(&"2.1.2".tostring(), "world!".tostring()); asserteq!(store.get(&"2.1.x".tostring()).unwrap(), &"world"); asserteq!(store.get(&"2.1".tostring()).unwrap(), &"world"); ```

remove

Removes a given version from the store.

```rust let mut store = SemverStore::::new(); store.insert(&"1.0.0".tostring(), "hello!".tostring()); asserteq!(store.get(&"1.0.0".tostring()).unwrap(), &"hello");

store.remove(&"1.0.0".tostring()); asserteq!(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.

```rust let mut store = SemverStore::::new(); store.insert(&"1.0.0".tostring(), "hello!".tostring()); store.insert(&"1.1.0".tostring(), "hello!".tostring()); asserteq!(store.get(&"1.0.0".tostring()).unwrap(), &"hello");

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

empty

Empties the store.

```rust let mut store = SemverStore::::new(); store.insert(&"1.0.0".tostring(), "hello!".tostring()); asserteq!(store.get(&"1.0.0".tostring()).unwrap(), &"hello");

store.empty(); asserteq!(store.get(&"1.0.0".tostring()), None); ```

License

MIT