pub struct Id<T: PrefixedId> { /* private fields */ }
Implementations§
Source§impl<T: PrefixedId> Id<T>
impl<T: PrefixedId> Id<T>
pub fn unprefixed(&self) -> Ulid
Methods from Deref<Target = Ulid>§
Sourcepub fn datetime(&self) -> SystemTime
pub fn datetime(&self) -> SystemTime
Gets the datetime of when this Ulid was created accurate to 1ms
§Example
use std::time::{SystemTime, Duration};
use ulid::Ulid;
let dt = SystemTime::now();
let ulid = Ulid::from_datetime(dt);
assert!(
dt + Duration::from_millis(1) >= ulid.datetime()
&& dt - Duration::from_millis(1) <= ulid.datetime()
);
pub const TIME_BITS: u8 = 48u8
pub const RAND_BITS: u8 = 80u8
Sourcepub fn timestamp_ms(&self) -> u64
pub fn timestamp_ms(&self) -> u64
Gets the timestamp section of this ulid
§Example
use std::time::{SystemTime, Duration};
use ulid::Ulid;
let dt = SystemTime::now();
let ulid = Ulid::from_datetime(dt);
assert_eq!(u128::from(ulid.timestamp_ms()), dt.duration_since(SystemTime::UNIX_EPOCH).unwrap_or(Duration::ZERO).as_millis());
Sourcepub fn random(&self) -> u128
pub fn random(&self) -> u128
Gets the random section of this ulid
§Example
use ulid::Ulid;
let text = "01D39ZY06FGSCTVN4T2V9PKHFZ";
let ulid = Ulid::from_string(text).unwrap();
let ulid_next = ulid.increment().unwrap();
assert_eq!(ulid.random() + 1, ulid_next.random());
Sourcepub fn to_str<'buf>(
&self,
buf: &'buf mut [u8],
) -> Result<&'buf mut str, EncodeError>
👎Deprecated since 1.2.0: Use the infallible array_to_str
instead.
pub fn to_str<'buf>( &self, buf: &'buf mut [u8], ) -> Result<&'buf mut str, EncodeError>
array_to_str
instead.Creates a Crockford Base32 encoded string that represents this Ulid
§Example
use ulid::Ulid;
let text = "01D39ZY06FGSCTVN4T2V9PKHFZ";
let ulid = Ulid::from_string(text).unwrap();
let mut buf = [0; ulid::ULID_LEN];
let new_text = ulid.to_str(&mut buf).unwrap();
assert_eq!(new_text, text);
Sourcepub fn array_to_str<'buf>(&self, buf: &'buf mut [u8; 26]) -> &'buf mut str
pub fn array_to_str<'buf>(&self, buf: &'buf mut [u8; 26]) -> &'buf mut str
Creates a Crockford Base32 encoded string that represents this Ulid
§Example
use ulid::Ulid;
let text = "01D39ZY06FGSCTVN4T2V9PKHFZ";
let ulid = Ulid::from_string(text).unwrap();
let mut buf = [0; ulid::ULID_LEN];
let new_text = ulid.array_to_str(&mut buf);
assert_eq!(new_text, text);
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Creates a Crockford Base32 encoded string that represents this Ulid
§Example
use ulid::Ulid;
let text = "01D39ZY06FGSCTVN4T2V9PKHFZ";
let ulid = Ulid::from_string(text).unwrap();
assert_eq!(&ulid.to_string(), text);
Sourcepub fn is_nil(&self) -> bool
pub fn is_nil(&self) -> bool
Test if the Ulid is nil
§Example
use ulid::Ulid;
let ulid = Ulid::new();
assert!(!ulid.is_nil());
let nil = Ulid::nil();
assert!(nil.is_nil());
Trait Implementations§
Source§impl<'__expr, T: PrefixedId> AsExpression<Nullable<Uuid>> for &'__expr Id<T>
impl<'__expr, T: PrefixedId> AsExpression<Nullable<Uuid>> for &'__expr Id<T>
Source§fn as_expression(self) -> <Self as AsExpression<Nullable<Uuid>>>::Expression
fn as_expression(self) -> <Self as AsExpression<Nullable<Uuid>>>::Expression
Perform the conversion
Source§impl<T: PrefixedId> AsExpression<Nullable<Uuid>> for Id<T>
impl<T: PrefixedId> AsExpression<Nullable<Uuid>> for Id<T>
Source§fn as_expression(self) -> <Self as AsExpression<Nullable<Uuid>>>::Expression
fn as_expression(self) -> <Self as AsExpression<Nullable<Uuid>>>::Expression
Perform the conversion
Source§impl<'__expr, T: PrefixedId> AsExpression<Uuid> for &'__expr Id<T>
impl<'__expr, T: PrefixedId> AsExpression<Uuid> for &'__expr Id<T>
Source§type Expression = Bound<Uuid, &'__expr Id<T>>
type Expression = Bound<Uuid, &'__expr Id<T>>
The expression being returned
Source§fn as_expression(self) -> <Self as AsExpression<Uuid>>::Expression
fn as_expression(self) -> <Self as AsExpression<Uuid>>::Expression
Perform the conversion
Source§impl<T: PrefixedId> AsExpression<Uuid> for Id<T>
impl<T: PrefixedId> AsExpression<Uuid> for Id<T>
Source§type Expression = Bound<Uuid, Id<T>>
type Expression = Bound<Uuid, Id<T>>
The expression being returned
Source§fn as_expression(self) -> <Self as AsExpression<Uuid>>::Expression
fn as_expression(self) -> <Self as AsExpression<Uuid>>::Expression
Perform the conversion
Source§impl<T: PrefixedId> Clone for Id<T>
impl<T: PrefixedId> Clone for Id<T>
Source§impl<T: PrefixedId> Debug for Id<T>
impl<T: PrefixedId> Debug for Id<T>
Source§impl<T: PrefixedId> Default for Id<T>
impl<T: PrefixedId> Default for Id<T>
Source§impl<T> Deref for Id<T>where
T: PrefixedId,
impl<T> Deref for Id<T>where
T: PrefixedId,
Source§impl<T: PrefixedId> Display for Id<T>
impl<T: PrefixedId> Display for Id<T>
Source§impl<T: PrefixedId> FromStr for Id<T>
impl<T: PrefixedId> FromStr for Id<T>
Source§impl<T: PrefixedId> Hash for Id<T>
impl<T: PrefixedId> Hash for Id<T>
Source§impl<T: PrefixedId> PartialEq for Id<T>
impl<T: PrefixedId> PartialEq for Id<T>
Source§impl<T: PrefixedId, __DB, __ST> Queryable<__ST, __DB> for Id<T>
impl<T: PrefixedId, __DB, __ST> Queryable<__ST, __DB> for Id<T>
Source§impl<T: PrefixedId> Serialize for Id<T>
impl<T: PrefixedId> Serialize for Id<T>
impl<T: PrefixedId> Copy for Id<T>
impl<T: PrefixedId> Eq for Id<T>
Auto Trait Implementations§
impl<T> Freeze for Id<T>
impl<T> RefUnwindSafe for Id<T>where
T: RefUnwindSafe,
impl<T> Send for Id<T>where
T: Send,
impl<T> Sync for Id<T>where
T: Sync,
impl<T> Unpin for Id<T>where
T: Unpin,
impl<T> UnwindSafe for Id<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T, ST, DB> FromSqlRow<ST, DB> for Twhere
T: Queryable<ST, DB>,
ST: SqlTypeOrSelectable,
DB: Backend,
<T as Queryable<ST, DB>>::Row: FromStaticSqlRow<ST, DB>,
impl<T, ST, DB> FromSqlRow<ST, DB> for Twhere
T: Queryable<ST, DB>,
ST: SqlTypeOrSelectable,
DB: Backend,
<T as Queryable<ST, DB>>::Row: FromStaticSqlRow<ST, DB>,
Source§impl<T, ST, DB> FromStaticSqlRow<ST, DB> for T
impl<T, ST, DB> FromStaticSqlRow<ST, DB> for T
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self
to an expression for Diesel’s query builder. Read moreSource§impl<T, ST, DB> StaticallySizedRow<ST, DB> for T
impl<T, ST, DB> StaticallySizedRow<ST, DB> for T
Source§const FIELD_COUNT: usize = <ST as crate::util::TupleSize>::SIZE
const FIELD_COUNT: usize = <ST as crate::util::TupleSize>::SIZE
The number of fields that this type will consume.