letter-sequence

Crates.ioletter-sequence
lib.rsletter-sequence
version2.1.0
sourcesrc
created_at2021-09-09 11:45:30.161908
updated_at2022-07-09 16:29:26.050881
descriptionA method to create sequence displayed as uppercase or lower letters, or digits
homepage
repository
max_upload_size
id448834
size55,462
Evan Carroll (EvanCarroll)

documentation

README

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" );
Commit count: 0

cargo fmt