Struct ulid_generator_rs::ULID
source · pub struct ULID(/* private fields */);
Expand description
This struct is ULID.
Implementations§
source§impl ULID
impl ULID
implements for ULID.
sourcepub fn new(value: u128) -> Self
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"
sourcepub const fn most_significant_bits(&self) -> u64
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();
sourcepub const fn least_significant_bits(&self) -> u64
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();
sourcepub const fn to_epoch_milli_as_long(&self) -> i64
pub const fn to_epoch_milli_as_long(&self) -> i64
sourcepub fn to_date_time(&self) -> DateTime<Local>
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();
sourcepub fn parse_from_byte_array(
byte_array: Vec<u8>,
endian: Endian
) -> Result<Self, ULIDError>
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 Ord for ULID
impl Ord for ULID
source§impl PartialEq for ULID
impl PartialEq for ULID
source§impl PartialOrd for ULID
impl PartialOrd for ULID
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl TryFrom<Vec<u8>> for ULID
impl TryFrom<Vec<u8>> for ULID
impl Copy for ULID
impl Eq for ULID
impl Send for ULID
impl StructuralPartialEq for ULID
impl Sync for ULID
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more