SequenceBuilder

Struct SequenceBuilder 

Source
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§

Source§

impl SequenceBuilder

Source

pub fn new() -> Self

Source

pub fn end(self, end: u64) -> Self

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

Source

pub fn start(self, start: u64) -> Self

Sets the start

Source

pub fn step(self, step: u32) -> Self

Sets the increment to step to

Source

pub fn max_render_capacity(self, chars: u8) -> Self

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 );
Source

pub fn min_render_length(self, chars: u8) -> Self

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

Source

pub fn exclusive(self) -> Self

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

Source

pub fn inclusive(self) -> Self

Close the range, include the end

Source

pub fn lower(self) -> Self

Render the sequence in lowercase

Source

pub fn upper(self) -> Self

Render the sequence in uppercase, default

Source

pub fn numeric(self) -> Self

Render the sequence in digits

Source

pub fn build(self) -> Result<Sequence, SequenceError>

Trait Implementations§

Source§

impl Debug for SequenceBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SequenceBuilder

Source§

fn default() -> Self

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

impl From<u64> for SequenceBuilder

Source§

fn from(start: u64) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<&str> for SequenceBuilder

// 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"
// );
Source§

type Error = SequenceError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<(&str, &str)> for SequenceBuilder

Source§

type Error = SequenceError

The type returned in the event of a conversion error.
Source§

fn try_from((start, end): (&str, &str)) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<char> for SequenceBuilder

Source§

type Error = SequenceError

The type returned in the event of a conversion error.
Source§

fn try_from(value: char) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.