[][src]Struct ulid_generator_rs::ULID

pub struct ULID(_);

This struct is ULID.

Implementations

impl ULID[src]

implements for ULID.

#[must_use]pub fn new(value: u128) -> Self[src]

The Constructor for ULID.

Example

ULID::new() is used to create a ULID instance, but usually ULIDGenerator is used.

use ulid_generator_rs::{ULID, ULIDGenerator};

let ulid: ULID = ULID::new(1945530789360716160560926739305506752);

// Use `ULIDGenerator::generate` as follows
let ulid: ULID = ULIDGenerator::new().generate().unwrap();

#[must_use]pub fn to_string(&self) -> String[src]

Converts a ULID to a string representation.

Example

use ulid_generator_rs::ULIDGenerator;

let ulid = ULIDGenerator::new().generate().unwrap();
let str = ulid.to_string();
println!("{}", str); // "01ETGRM6448X1HM0PYWG2KT648"

pub fn increment(&self) -> Self[src]

Increment this ULID.

Example

use ulid_generator_rs::ULIDGenerator;
let ulid = ULIDGenerator::new().generate().unwrap();
let next_ulid = ulid.increment();

#[must_use]pub const fn most_significant_bits(&self) -> u64[src]

Most significant bits.

Example

use ulid_generator_rs::{ULIDGenerator, ULID};

let ulid: ULID = ULIDGenerator::new().generate().unwrap();
let m: u64 = ulid.most_significant_bits();

#[must_use]pub const fn least_significant_bits(&self) -> u64[src]

Least significant bits.

Example

use ulid_generator_rs::{ULIDGenerator, ULID};

let ulid: ULID = ULIDGenerator::new().generate().unwrap();
let l: u64 = ulid.least_significant_bits();

#[must_use]pub const fn to_epoch_milli_as_long(&self) -> i64[src]

Converts a ULID to a epoch time as milli seconds.

Example

use ulid_generator_rs::{ULIDGenerator, ULID};

let ulid: ULID = ULIDGenerator::new().generate().unwrap();
let epoch: i64 = ulid.to_epoch_milli_as_long();

#[must_use]pub fn to_date_time(&self) -> DateTime<Local>[src]

Converts a ULID to a DateTime<Local>

Example

use ulid_generator_rs::{ULIDGenerator, ULID};
use chrono::{Local, DateTime};

let ulid: ULID = ULIDGenerator::new().generate().unwrap();
let date_time: DateTime<Local> = ulid.to_date_time();

#[must_use]pub fn to_byte_array(&self, endian: Endian) -> Vec<u8>[src]

Converts a ULID to a byte array.

endian a Endian of byte array

Example

use ulid_generator_rs::{ULIDGenerator, ULID, Endian};

let ulid: ULID = ULIDGenerator::new().generate().unwrap();
let ba: Vec<u8> = ulid.to_byte_array(Endian::BE);

pub fn parse_from_byte_array(
    byte_array: Vec<u8>,
    endian: Endian
) -> Result<Self, ULIDError>
[src]

Parse a byte array as ULID.

byte_array a byte array as ULID. endian a Endian of byte_array.

Example

use ulid_generator_rs::{ULIDGenerator, ULID, Endian};

let ulid: ULID = ULIDGenerator::new().generate().unwrap();
let ba: Vec<u8> = ulid.to_byte_array(Endian::BE);
let ulid: ULID = ULID::parse_from_byte_array(ba, Endian::BE).unwrap();

Trait Implementations

impl Clone for ULID[src]

impl Debug for ULID[src]

impl Display for ULID[src]

impl From<(u64, u64)> for ULID[src]

pub fn from((most_significant_bits, least_significant_bits): (u64, u64)) -> Self[src]

use ulid_generator_rs::ULID;

let ulid: ULID = (105449255778666307, 1874305465861347464).into();

impl From<u128> for ULID[src]

pub fn from(value: u128) -> Self[src]

use ulid_generator_rs::ULID;

let ulid: ULID = 1945530789360716160560926739305506752.into();

impl FromStr for ULID[src]

type Err = ULIDError

The associated error which can be returned from parsing.

pub fn from_str(ulid_str: &str) -> Result<Self, Self::Err>[src]

use ulid_generator_rs::ULID;

let ulid: ULID = "01ETGRM6448X1HM0PYWG2KT648".parse::<ULID>().unwrap();

impl PartialEq<ULID> for ULID[src]

impl PartialOrd<ULID> for ULID[src]

impl StructuralPartialEq for ULID[src]

impl TryFrom<Vec<u8, Global>> for ULID[src]

type Error = ULIDError

The type returned in the event of a conversion error.

pub fn try_from(value: Vec<u8>) -> Result<Self, Self::Error>[src]

use ulid_generator_rs::{ULID, Endian};
use std::convert::TryInto;

let ulid: ULID = 1945530789360716160560926739305506752.into();
let bytes: Vec<u8> = ulid.to_byte_array(Endian::BE);
let ulid: ULID = bytes.try_into().unwrap();

Auto Trait Implementations

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,