Struct LightId

Source
pub struct LightId {
    pub characters: Vec<char>,
    pub min_length: usize,
    /* private fields */
}

Fields§

§characters: Vec<char>§min_length: usize

Implementations§

Source§

impl LightId

Source

pub fn new() -> Self

Creates a new LightId with the default configuration.

use light_id::LightId;

let mut generator = LightId::new();
Source

pub fn from<S: AsRef<str>>(characters: S) -> Self

Creates a new LightId with a custom alphabet

use light_id::LightId;

let generator = LightId::from("abcdef");

If the provided characters is equal to DEFAULT_CHARACTERS, the expression can be replaced with

use light_id::LightId;

let generator = LightId::new();
Source

pub fn skip(&mut self, n: usize) -> &mut Self

Skip the first n ids

use light_id::LightId;

let mut generator = LightId::new();

generator.skip(2);

assert_eq!("2", generator.current());
Source

pub fn last<S: AsRef<str>>(&mut self, id: S) -> &mut Self

Skips the first ids until the provided id.

use light_id::LightId;

let mut generator = LightId::new();

generator.last("c");

assert_eq!("c", generator.current());
Source

pub fn min(&mut self, n: usize) -> &mut Self

Sets the min length of the ids

use light_id::LightId;

let mut generator = LightId::new();

generator.min(6);

assert_eq!("000000", generator.current());
Source

pub fn chars<S: AsRef<str>>(&mut self, characters: S) -> &mut Self

Sets the possible characters, in their order of importance (custom base)

use light_id::LightId;

let mut generator = LightId::new();

generator.chars("abc");

assert_eq!("a", generator.current());
Source

pub fn clone(&self) -> Self

Clone the current [LighId].

use light_id::LightId;

let mut generator = LightId::new();

let mut generator2 = generator.clone();
Source

pub fn count(&self) -> usize

Returns the current number of ids

use light_id::LightId;

let mut generator = LightId::new();

generator.increment();

assert_eq!(1, generator.count());
Source

pub fn decrement(&mut self) -> &mut Self

Decrements the current id. Internally uses an alias to LightId::decrement_by

use light_id::LightId;

let mut generator = LightId::new();

generator.increment();
generator.decrement();

assert_eq!("0", generator.current());
Source

pub fn decrement_by(&mut self, count: usize) -> &mut Self

Decrements the current id with a given factor

use light_id::LightId;

let mut generator = LightId::new();

generator.increment_by(10);
generator.decrement_by(10);

assert_eq!("0", generator.current());
Source

pub fn increment(&mut self) -> &mut Self

Increments the current id by one. Internally uses an alias to LightId::increment_by

use light_id::LightId;

let mut generator = LightId::new();

generator.increment();

assert_eq!("1", generator.current());
Source

pub fn increment_by(&mut self, count: usize) -> &mut Self

Increments the current id with a given factor

use light_id::LightId;

let mut generator = LightId::new();

generator.increment_by(10);

assert_eq!("a", generator.current());
Source

pub fn next(&mut self) -> String

Increments the id by one and returns it.

use light_id::LightId;

let mut generator = LightId::new();

assert_eq!("0", generator.next());
assert_eq!("1", generator.next());
assert_eq!("2", generator.next());

Internally uses an alias to LightId::current and LightId::increment

use light_id::LightId;

let mut generator = LightId::new();

let value = generator.current();
generator.increment();

assert_eq!("0", value);
Source

pub fn current(&self) -> String

Returns the current id.

use light_id::LightId;

let mut generator = LightId::new();

assert_eq!("0", generator.current());
Source

pub fn len(&self) -> usize

Returns the length of the current id.

use light_id::LightId;

let mut generator = LightId::new();

assert_eq!(1, generator.len());

generator.increment_by(100);

assert_eq!(2, generator.len());
Source

pub fn nth(&self, n: usize) -> String

Returns the nth id.

use light_id::LightId;
 
let generator = LightId::new();
 
assert_eq!("2", generator.nth(2));
Source

pub fn index<S: AsRef<str>>(&self, id: S) -> usize

Returns the index of the provided id

use light_id::LightId;
 
let generator = LightId::new();
 
assert_eq!(2, generator.index("2"));

Trait Implementations§

Source§

impl PartialEq for LightId

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for LightId

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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.