semver-store

An HashMap structure that uses semver strings as keys.

Install

sh cargo add semver-store

API

set

Add a value to the store for a given version.

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

get

Get the reference fo a stored value.

rust let mut store = SemverStore::<String>::new(); store.set("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.set("1.0.0".tostring(), "hello!".tostring()); store.set("1.1.0".tostring(), "world!".tostring()); asserteq!(store.get("1.x".tostring()).unwrap(), &"world");

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

del

Removes a given version from the store.

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

store.del("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.set("1.0.0".tostring(), "hello!".tostring()); store.set("1.1.0".tostring(), "hello!".tostring()); asserteq!(store.get("1.0.0".tostring()).unwrap(), &"hello");

store.del("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.set("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