[][src]Struct alphaid::AlphaId

pub struct AlphaId<T: UnsignedInteger = u128> { /* fields omitted */ }

Used for encoding and decoding.

Implementations

impl<T: UnsignedInteger> AlphaId<T>[src]

pub fn builder() -> Builder<T>[src]

Returns a builder type to configure a new AlphaId.

pub fn new() -> Self[src]

Creates a new AlphaId with a default configuration.

pub fn encode(&self, n: T) -> Result<Vec<u8>, AlphaIdError>[src]

Encode the numbers.

Example

use alphaid::AlphaId;

let alphaid = AlphaId::<u32>::new();
assert_eq!(alphaid.encode(0), Ok(b"a".to_vec()));
assert_eq!(alphaid.encode(1), Ok(b"b".to_vec()));
assert_eq!(alphaid.encode(1350997667), Ok(b"90F7qb".to_vec()));

pub fn decode<V: AsRef<[u8]>>(&self, v: V) -> Result<T, AlphaIdError>[src]

Decode into numbers.

Example

use alphaid::AlphaId;

let alphaid = AlphaId::<u32>::new();
assert_eq!(alphaid.decode(b"a"), Ok(0));
assert_eq!(alphaid.decode(b"b"), Ok(1));
assert_eq!(alphaid.decode(b"90F7qb"), Ok(1350997667));

Auto Trait Implementations

impl<T> RefUnwindSafe for AlphaId<T> where
    T: RefUnwindSafe

impl<T> Send for AlphaId<T> where
    T: Send

impl<T> Sync for AlphaId<T> where
    T: Sync

impl<T> Unpin for AlphaId<T> where
    T: Unpin

impl<T> UnwindSafe for AlphaId<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.