IdSwitcher

Struct IdSwitcher 

Source
pub struct IdSwitcher { /* private fields */ }

Implementations§

Source§

impl IdSwitcher

Source

pub fn new<S: AsRef<str>>(source: S, target: S) -> Self

Create a new IdSwitcher. It can be used to switch the ids from a source base to a target base.

use light_id::IdSwitcher;
 
let switcher = IdSwitcher::new("0123456789", "abcdefghij");
Source

pub fn clone(&self) -> Self

Returns a copy of the IdSwitcher.

use light_id::IdSwitcher;
 
let switcher = IdSwitcher::new("0123456789", "abcdefghij");
let switcher_2 = switcher.clone();
Source

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

Sets the min length of the converted ids.

use light_id::IdSwitcher;
 
let mut switcher = IdSwitcher::new("0123456789", "abcdefghij");
 
switcher.min_target(10);
 
assert_eq!("aaaaaaaaaa", switcher.switch("0"));
Source

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

Sets the min length of the source ids.

use light_id::IdSwitcher;
 
let mut switcher = IdSwitcher::new("0123456789", "abcdefghij");
 
switcher.min_source(10);
 
assert_eq!("0000000000", switcher.switch_reverse("a"));
Source

pub fn switch_count(&self, id: usize) -> String

Switches an id count from the source base to the target base.

use light_id::IdSwitcher;
 
let switcher = IdSwitcher::new("0123456789", "abcdefghij");
 
assert_eq!("a", switcher.switch_count(0));
Source

pub fn switch<S: AsRef<str>>(&self, id: S) -> String

Switches an id from the source base to the target base.

use light_id::IdSwitcher;
 
let switcher = IdSwitcher::new("0123456789", "abcdefghij");
 
assert_eq!("a", switcher.switch("0"));
Source

pub fn switch_count_reverse(&self, id: usize) -> String

Switches an id count from the target base to the source base.

use light_id::IdSwitcher;
 
let switcher = IdSwitcher::new("0123456789", "abcdefghij");
 
assert_eq!("0", switcher.switch_count_reverse(0));
Source

pub fn switch_reverse<S: AsRef<str>>(&self, id: S) -> String

Switches an id from the target base to the source base.

use light_id::IdSwitcher;
 
let switcher = IdSwitcher::new("0123456789", "abcdefghij");
 
assert_eq!("0", switcher.switch_reverse("a"));

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.