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

semver-store

使用 semver 字符串作为键的 HashMap 结构。

2 个不稳定版本

0.2.0 2019 年 9 月 10 日
0.1.0 2019 年 9 月 3 日

#2117数据结构

MIT 许可证

19KB
369

semver-store

Crates.io Crates.io

使用 semver 字符串作为键的 HashMap 结构。

安装

cargo add semver-store

API

insert

为给定版本添加值到存储中。

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

contains_key

检查键是否已插入。

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

获取存储值的引用。

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");

支持通配符!如果您使用通配符,您将始终获得给定主要/次要版本的最大版本。

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

从存储中删除给定版本。

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);

支持通配符!如果您使用通配符,您将始终删除给定主要/次要版本的最大版本。

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

清空存储。

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);

许可证

MIT

无运行时依赖