Crates.io | letter-sequence |
lib.rs | letter-sequence |
version | 2.1.0 |
source | src |
created_at | 2021-09-09 11:45:30.161908 |
updated_at | 2022-07-09 16:29:26.050881 |
description | A method to create sequence displayed as uppercase or lower letters, or digits |
homepage | |
repository | |
max_upload_size | |
id | 448834 |
size | 55,462 |
Letter-Sequence is a crate that gives you the ability to create sequences more complex then simple ordinal digits.
+=
and -=
An uppercase sequence, unbounded by rendering output
use letter_sequence::SequenceBuilder;
use std::convert::TryFrom;
let mut seq = SequenceBuilder::try_from("A")
.unwrap()
.upper()
.build()
.unwrap();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "A" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "B" );
seq.set(25).unwrap();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "Z" );
let elem = seq.nth(3).unwrap();
assert_eq!( elem.to_string(), "AD" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "AE" );
This time with .max_render_capacity()
set, and .lower()
cased
use letter_sequence::SequenceBuilder;
use std::convert::TryFrom;
let mut seq = SequenceBuilder::try_from("y")
.unwrap()
.lower()
.max_render_capacity(1)
.build()
.unwrap();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "y" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "z" );
let elem = seq.next();
assert_eq!( elem, None );
Also supports bounded and unbounded numeric sequences
use letter_sequence::SequenceBuilder;
use std::convert::From;
let mut seq = SequenceBuilder::from(99)
.numeric()
.max_render_capacity(3)
.build()
.unwrap();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "99" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "100" );