Struct ulid_generator_rs::ULID

source ·
pub struct ULID(_);
Expand description

This struct is ULID.

Implementations§

source§

impl ULID

implements for ULID.

source

pub fn new(value: u128) -> Self

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 mut generator: ULIDGenerator = ULIDGenerator::new();
let ulid: ULID = generator.generate().unwrap();
println!("{}", ulid); // "01ETGRM6448X1HM0PYWG2KT648"
source

pub fn to_string(&self) -> String

Converts a ULID to a string representation.

Example
use ulid_generator_rs::{ULIDGenerator, ULID};

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

pub fn increment(&self) -> Self

Increment this ULID.

Example
use ulid_generator_rs::{ULIDGenerator, ULID};

let mut generator: ULIDGenerator = ULIDGenerator::new();
let ulid: ULID = generator.generate().unwrap();
let next_ulid: ULID = ulid.increment();
source

pub const fn most_significant_bits(&self) -> u64

Most significant bits.

Example
use ulid_generator_rs::{ULIDGenerator, ULID};

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

pub const fn least_significant_bits(&self) -> u64

Least significant bits.

Example
use ulid_generator_rs::{ULIDGenerator, ULID};

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

pub const fn to_epoch_milli_as_long(&self) -> i64

Converts a ULID to a epoch time as milli seconds.

Example
use ulid_generator_rs::{ULIDGenerator, ULID};

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

pub fn to_date_time(&self) -> DateTime<Local>

Converts a ULID to a DateTime<Local>

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

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

pub fn to_byte_array(&self, endian: Endian) -> Vec<u8>

Converts a ULID to a byte array.

endian a Endian of byte array

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

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

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

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 mut generator: ULIDGenerator = ULIDGenerator::new();
let ulid: ULID = generator.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§

source§

impl Clone for ULID

source§

fn clone(&self) -> ULID

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ULID

source§

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

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

impl Display for ULID

source§

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

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

impl From<(u64, u64)> for ULID

source§

fn from((most_significant_bits, least_significant_bits): (u64, u64)) -> Self

use ulid_generator_rs::ULID;

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

impl From<u128> for ULID

source§

fn from(value: u128) -> Self

use ulid_generator_rs::ULID;

let ulid: ULID = 1945530789360716160560926739305506752.into();
source§

impl FromStr for ULID

source§

fn from_str(ulid_str: &str) -> Result<Self, Self::Err>

use ulid_generator_rs::ULID;

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

type Err = ULIDError

The associated error which can be returned from parsing.
source§

impl Hash for ULID

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for ULID

source§

fn cmp(&self, other: &ULID) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<ULID> for ULID

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<ULID> for ULID

source§

fn partial_cmp(&self, other: &ULID) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<Vec<u8, Global>> for ULID

source§

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

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();
§

type Error = ULIDError

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

impl Copy for ULID

source§

impl Eq for ULID

source§

impl Send for ULID

source§

impl StructuralEq for ULID

source§

impl StructuralPartialEq for ULID

source§

impl Sync for ULID

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V