granular-id
This crate provides a data type GranularId<T> that can represent ID numbers with arbitrary precision.
Features
GranularId<T>is a sequence of components of typeTthat can be ordered and compared.- Between any two
GranularId<T>s, there are infinitely many more granular IDs. GranularId<T>is best used with any unsized integer type, such asu8,u16,u32, etc.GranularId<T>can also be used with any type that implements the appropriatenum_traits.GranularId<T>has methods to access its parent, children, siblings, and other relations in a tree-like structure.
Example usage
// Create a new GranularId from a vec of u8 (id: 1.2.3)
let id: = vec!.into;
// Get the parent ID (id: 1.2)
let parent = id.parent;
assert_eq!;
// Iterate over the following siblings of 1.2.3
let mut next_siblings = id.next_siblings;
// First one is 1.2.4
assert_eq!;
// Then, 1.2.5, etc
assert_eq!;
assert_eq!;
// Get an iterator over childrens of 1.2.3
let mut children = id.children;
// First one is 1.2.3.0
assert_eq!;
// Then, 1.2.3.1, etc
assert_eq!;
assert_eq!;
// Each parent is always smaller than all of its children
assert!;
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
License
This project is licensed under the MIT license. See LICENSE for more details.