Crates.io | digit-sequence |
lib.rs | digit-sequence |
version | 0.3.8 |
source | src |
created_at | 2024-03-06 20:49:29.862393 |
updated_at | 2024-09-19 02:16:05.305748 |
description | Sequence of u8 digits |
homepage | |
repository | https://github.com/giancosta86/digit-sequence |
max_upload_size | |
id | 1165205 |
size | 33,781 |
Sequence of u8 digits
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(())
}
This crate supports the following optional features:
serde
: enables JSON conversions via serdehttps://crates.io/crates/digit-sequence
https://docs.rs/digit-sequence