Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fightling/ord-collections
https://github.com/fightling/ord-collections
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fightling/ord-collections
- Owner: fightling
- Created: 2024-02-16T11:42:22.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-08-19T20:46:16.000Z (5 months ago)
- Last Synced: 2024-10-10T19:11:16.684Z (3 months ago)
- Language: Rust
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ord-collections
[![Status](https://github.com/fightling/ord-collections/actions/workflows/rust.yml/badge.svg)](https://github.com/fightling/ord-collections/actions)
[![Crates.io](https://img.shields.io/crates/v/ord-collections.svg)](https://crates.io/crates/ord-collections)
[![Documentation](https://docs.rs/ord-collections/badge.svg)](https://docs.rs/ord-collections/)
[![Dependency status](https://deps.rs/repo/github/fightling/ord-collections/status.svg)](https://deps.rs/repo/github/fightling/ord-collections)## Examples
### OrdVec
```rs
use ord_collections:: {Error,OrdVec};let mut index: OrdVec = OrdVec::default();
// insert `1`, `2`, `3` in wrong order
assert!(index.insert(1).is_ok());
assert!(index.insert(3).is_ok());
assert!(index.insert(2).is_ok());// check that we cannot push `1` again
assert!(matches!(
index.insert(1),
Err(Error::Duplicate(_))
));// check that iteration is in expected order
let mut sorted = String::new();
for i in index.iter() {
sorted += &i.to_string()
}
assert_eq!(sorted, "123");assert!(index.insert(1).is_err());
```### OrdMap
```rs
use ord_collections::{OrdMap,Indexed,Error};let mut index: OrdMap = OrdMap::default();
// insert `A`, `B`, `C` in wrong order
assert!(index.insert(Indexed::new('C', 0)).is_ok());
assert!(index.insert(Indexed::new('A', 0)).is_ok());
assert!(index.insert(Indexed::new('B', 0)).is_ok());// check that we cannot insert `A` again
assert!(matches!(
index.insert(Indexed::new('A', 0)),
Err(Error::Duplicate(_))
));check that iteration is in expected order
let mut sorted = String::new();
for i in index.iter() {
sorted += &i.index().to_string()
}
assert_eq!(sorted, "ABC");assert!(index.insert(Indexed::new('A', 1)).is_err());
```