#collection #data #unsigned-integer

sequential

A configurable sequential number generator

4 releases (2 breaking)

0.5.1 Jan 27, 2025
0.5.0 Dec 24, 2024
0.4.0 Dec 24, 2024
0.3.0 Dec 24, 2024

#735 in Encoding

Download history 185/week @ 2024-12-18 139/week @ 2024-12-25 2/week @ 2025-01-08 77/week @ 2025-01-22 23/week @ 2025-01-29

102 downloads per month

MIT/Apache

18KB
371 lines

Latest version Build Documentation License unsafe forbidden

sequential is a tiny library that provides with Sequence a sequential number generator that

  • produces monotonously increasing integer numbers, starting from a configurable starting point and with a configurable increment
  • can be fast-forwarded to skip numbers, but cannot be wound back
  • stops producing values when the limit of the chosen type T is reached
  • optionally (with feature serde) implements serde's Serialize and Deserialize so that its state can be persisted
  • works with all unsigned integers, from u8 to u128, and with usize.
  • strictly uses checked_* arithmetics to avoid panic caused by number overflow.

Usage

Add sequential to the dependencies section in your project's Cargo.toml

[dependencies]
sequential = "0.5"

Example

let mut sequence = Sequence::<usize>::new();

assert_eq!(sequence.next(), Some(0_u8));
assert_eq!(sequence.next(), Some(1_u8));

Features

serde (optional)

Adds the serialization and deserialization capability.

Dependencies

The library has no external dependency except the optional one to serde.

Dependencies

~155KB