11 releases (5 stable)
2.1.0 | Jul 9, 2022 |
---|---|
1.0.1 | Jun 22, 2022 |
0.6.0 | Oct 12, 2021 |
#779 in Text processing
26 downloads per month
47KB
1K
SLoC
letter-sequence
Letter-Sequence is a crate that gives you the ability to create sequences more complex then simple ordinal digits.
Features
- Render-binding - limit a sequence by the rendered output
- Render a sequence in uppercase, lowercase, or as numeric.
- Mutate a sequence with another sequence using
+=
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" );
Dependencies
~1.6–2.2MB
~48K SLoC