# inc-id

A `no_std` library for generating reusable auto-incrementing identifiers (`alloc` is still required).

Incrementing values can make great unique identifiers because
1. they do not need to be large to prevent collisions
2. are always unique until they reach their max value
3. have minimal performance impact because it relies on simple adding rather than hashing or randomizing.

This crate provides a generator that outputs serial values. Unsigned integers from the standard library
are supported by default, but any type can be supported simply by implementing the `IncrementableId`
trait.

For safety and stability, the generator prevents overflows by returning a `Result`, which will be an error
if the next generated value would exceed the maximum value for the type (e.g. `u32::MAX`).

If ids are never returned, ids will always be issued in increasing order. If you don't want ids to be
reused, don't return them to the generator.

**Warning**: though there may be an observed pattern to how returned ids are reissued (increasing,
decreasing, LIFO, FIFO, etc.) this is considered an implementation detail of the library and may change
in future versions. For stability it is recommended to treat all generated ids as arbitrarily ordered
if the return functionality is used.

## Features
 - `no_std`
 - returnable ids for reuse through the generator
 - support for all unsigned integers in the standard library
 - iterator implementation
 - serde support via `serde` feature flag
 - no dependencies
 - support custom serial types with single trait

## Usage
Use a generator to create unique identifiers.

```rust
let mut id_gen = IdGenerator::<u32>::new();

assert_eq!(0, id_gen.get_id());
assert_eq!(1, id_gen.get_id());
```

## License
This library is licensed under your choice of MIT or Apache 2.0
