digit-sequence

Crates.iodigit-sequence
lib.rsdigit-sequence
version0.3.8
sourcesrc
created_at2024-03-06 20:49:29.862393
updated_at2024-09-19 02:16:05.305748
descriptionSequence of u8 digits
homepage
repositoryhttps://github.com/giancosta86/digit-sequence
max_upload_size
id1165205
size33,781
Gianluca Costa (giancosta86)

documentation

README

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

Commit count: 19

cargo fmt