pub struct SequenceBuilder { /* private fields */ }
Expand description
use letter_sequence::SequenceBuilder;
use std::convert::TryFrom;

let mut seq = SequenceBuilder::try_from("Z")
  .unwrap()
	.upper()
	.build()
	.unwrap();
// First call to .next() returns starting element
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "Z" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "AA" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "AB" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "AC" );

This time with .max_render_capacity() set, and lowercase

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"  );
// Without .max_render_capacity(1) this would return "aa"
let elem = seq.next();
assert_eq!( elem, None  );

Also boring number sequence

use letter_sequence::SequenceBuilder;
use std::convert::TryFrom;

let mut seq = SequenceBuilder::from(102)
	.numeric()
	.build()
	.unwrap();
let elem = seq.next();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "103" );

You can also set the step!

use letter_sequence::SequenceBuilder;
use std::convert::TryFrom;
 
let mut seq = SequenceBuilder::from(0)
	.numeric()
	.step(2)
	.build()
	.unwrap();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "0"  );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "2"  );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "4"  );

let mut seq = SequenceBuilder::try_from("A")
  .unwrap()
	.step(2)
	.upper()
	.build()
	.unwrap();
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "A" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "C" );
let elem = seq.next().unwrap();
assert_eq!( elem.to_string(), "E" );

Implementations

Sets the end, default half-open (exclusive end), see .inclusive()

Sets the start

Sets the increment to step to

Limits the chacters in rendered output, incrementing past limit generates error. default: unlimited

use letter_sequence::{ SequenceBuilder, SequenceError };
use std::convert::TryFrom;
let mut seq = SequenceBuilder::try_from("y").unwrap().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" );
assert_eq!( seq.next(), None );
assert_eq!( seq.next(), None );

Limits the minimum width of the rendered output, this only works on numeric which effectively zero-pads the output.

This is the default: a half-open range that excludes the end

Close the range, include the end

Render the sequence in lowercase

Render the sequence in uppercase, default

Render the sequence in digits

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

// use letter_sequence::SequenceBuilder;
// use std::convert::TryFrom;
// assert_eq!(
// 	SequenceBuilder::try_from("00001")
// 		.unwrap()
// 		.build()
// 		.unwrap()
// 		.to_string(),
// 	"1"
// );
// assert_eq!(
// 	SequenceBuilder::try_from("00001")
// 		.unwrap()
// 		.upper()
// 		.build()
// 		.unwrap()
// 		.to_string(),
// 	"B"
// );

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.