Struct letter_sequence::sequence::builder::SequenceBuilder[][src]

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

let mut seq = SequenceBuilder::try_from("Z")
  .unwrap()
	.upper()
	.build()
	.unwrap();
assert_eq!( seq.to_string(), "Z" );
seq.next();
assert_eq!( seq.to_string(), "AA" );
seq += 5u64;
assert_eq!( seq.to_string(), "AF" );

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();
assert_eq!( seq.next().unwrap().to_string(), "z"  );
assert_eq!( seq.to_string(),                 "z"  );
// Without .max_render_capacity(1) this would reutrn "aa"
assert_eq!( seq.next(),                      None );

Also boring number sequence

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

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

You can also set the step!

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

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

Implementations

Creates a new Sequence starting at start (0-base)

use letter_sequence::SequenceBuilder;

let seq = SequenceBuilder::new(2).upper().build().unwrap();
assert_eq!( seq.to_string(), "C" );

let seq = SequenceBuilder::new(5).build().unwrap();
assert_eq!( seq.to_string(), "5" );

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();
seq.inc().unwrap();
assert_eq!( seq.to_string(), String::from("z") );
assert_eq!( seq.inc().unwrap_err(), SequenceError::OutOfRange );

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

Set the increment to step to

Set the last value to increment to

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

Performs the conversion.

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.

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

Performs the conversion.

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.