12 releases

0.3.8 Sep 19, 2024
0.3.7 Sep 12, 2024
0.3.5 Jun 3, 2024
0.3.4 May 17, 2024
0.1.0 Mar 6, 2024

#523 in Data structures

46 downloads per month
Used in 2 crates

MIT license

32KB
452 lines

digit-sequence

Sequence of u8 digits

Crates.io Version

This Rust crate revolves around the DigitSequence struct, a sequence of 0-9 u8 digits, with:

  • conversions from integers, numeric sequences and strings

  • different iteration strategies

  • a custom Result and a custom Error.

  • optional serde I/O

use digit_sequence::*;

fn main() -> GenericResult<()> {
    assert_eq!(DigitSequence::new(), []);
    assert_eq!(DigitSequence::default(), []);

    let sequence: DigitSequence = [3, 8, 7].try_into()?;
    assert_eq!(sequence, [3, 8, 7]);

    assert_eq!(format!("{:?}", sequence), "DigitSequence([3, 8, 7])");
    assert_eq!(sequence.to_string(), "387");

    let mapped_vec: Vec<u8> = sequence.iter().map(|digit| digit + 1).collect();
    assert_eq!(mapped_vec, vec![4, 9, 8]);

    let number: u16 = sequence.try_into()?;
    assert_eq!(number, 387);

    Ok(())
}

Features

This crate supports the following optional features:

  • serde: enables JSON conversions via serde

Crates.io

https://crates.io/crates/digit-sequence

Documentation

https://docs.rs/digit-sequence

License

MIT

Dependencies

~160KB