Struct Id

Source
pub struct Id<T: PrefixedId> { /* private fields */ }

Implementations§

Source§

impl<T: PrefixedId> Id<T>

Source

pub fn unprefixed(&self) -> Ulid

Source§

impl<T: PrefixedId> Id<T>

Source

pub fn new() -> Self

Methods from Deref<Target = Ulid>§

Source

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

pub const TIME_BITS: u8 = 48u8

Source

pub const RAND_BITS: u8 = 80u8

Source

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

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

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

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);
Source

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);
Source

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);
Source

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

pub fn increment(&self) -> Option<Ulid>

Increment the random number, make sure that the ts millis stays the same

Source

pub fn to_bytes(&self) -> [u8; 16]

Returns the bytes of the Ulid in big-endian order.

§Example
use ulid::Ulid;

let text = "7ZZZZZZZZZZZZZZZZZZZZZZZZZ";
let ulid = Ulid::from_string(text).unwrap();

assert_eq!(ulid.to_bytes(), [0xFF; 16]);

Trait Implementations§

Source§

impl<'__expr, T: PrefixedId> AsExpression<Nullable<Uuid>> for &'__expr Id<T>

Source§

type Expression = Bound<Nullable<Uuid>, &'__expr Id<T>>

The expression being returned
Source§

fn as_expression(self) -> <Self as AsExpression<Nullable<Uuid>>>::Expression

Perform the conversion
Source§

impl<T: PrefixedId> AsExpression<Nullable<Uuid>> for Id<T>

Source§

type Expression = Bound<Nullable<Uuid>, Id<T>>

The expression being returned
Source§

fn as_expression(self) -> <Self as AsExpression<Nullable<Uuid>>>::Expression

Perform the conversion
Source§

impl<'__expr, T: PrefixedId> AsExpression<Uuid> for &'__expr Id<T>

Source§

type Expression = Bound<Uuid, &'__expr Id<T>>

The expression being returned
Source§

fn as_expression(self) -> <Self as AsExpression<Uuid>>::Expression

Perform the conversion
Source§

impl<T: PrefixedId> AsExpression<Uuid> for Id<T>

Source§

type Expression = Bound<Uuid, Id<T>>

The expression being returned
Source§

fn as_expression(self) -> <Self as AsExpression<Uuid>>::Expression

Perform the conversion
Source§

impl<T: PrefixedId> Clone for Id<T>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<T: PrefixedId> Debug for Id<T>

Source§

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

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

impl<T: PrefixedId> Default for Id<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Deref for Id<T>
where T: PrefixedId,

Source§

type Target = Ulid

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: PrefixedId> Display for Id<T>

Source§

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

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

impl<T, I> From<I> for Id<T>
where T: PrefixedId, I: Into<Ulid>,

Source§

fn from(id: I) -> Self

Converts to this type from the input type.
Source§

impl<T: PrefixedId> From<Id<T>> for Uuid

Source§

fn from(value: Id<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromSql<Uuid, Pg> for Id<T>
where T: PrefixedId,

Source§

fn from_sql(bytes: PgValue<'_>) -> Result<Self>

See the trait documentation.
Source§

fn from_nullable_sql( bytes: Option<<DB as Backend>::RawValue<'_>>, ) -> Result<Self, Box<dyn Error + Sync + Send>>

A specialized variant of from_sql for handling null values. Read more
Source§

impl<T: PrefixedId> FromStr for Id<T>

Source§

type Err = IdParseError

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

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

Parses a string s to return a value of this type. Read more
Source§

impl<T: PrefixedId> Hash for Id<T>

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<T: PrefixedId> PartialEq for Id<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PrefixedId, __DB, __ST> Queryable<__ST, __DB> for Id<T>
where __DB: Backend, __ST: SingleValue, Self: FromSql<__ST, __DB>,

Source§

type Row = Id<T>

The Rust type you’d like to map from. Read more
Source§

fn build(row: Self) -> Result<Self>

Construct an instance of this type
Source§

impl<T: PrefixedId> Serialize for Id<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PrefixedId, __DB> ToSql<Nullable<Uuid>, __DB> for Id<T>
where __DB: Backend, Self: ToSql<Uuid, __DB>,

Source§

fn to_sql<'__b>(&'__b self, out: &mut Output<'__b, '_, __DB>) -> Result

See the trait documentation.
Source§

impl<T> ToSql<Uuid, Pg> for Id<T>
where T: PrefixedId + Debug,

Source§

fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> Result

See the trait documentation.
Source§

impl<T: PrefixedId> Copy for Id<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, ST, DB> FromSqlRow<ST, DB> for T
where T: Queryable<ST, DB>, ST: SqlTypeOrSelectable, DB: Backend, <T as Queryable<ST, DB>>::Row: FromStaticSqlRow<ST, DB>,

Source§

fn build_from_row<'a>( row: &impl Row<'a, DB>, ) -> Result<T, Box<dyn Error + Sync + Send>>

See the trait documentation.
Source§

impl<T, ST, DB> FromStaticSqlRow<ST, DB> for T
where DB: Backend, T: FromSql<ST, DB>, ST: SingleValue,

Source§

fn build_from_row<'a>( row: &impl Row<'a, DB>, ) -> Result<T, Box<dyn Error + Sync + Send>>

See the trait documentation
Source§

impl<T, U> Into<U> for T
where 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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, ST, DB> StaticallySizedRow<ST, DB> for T
where ST: SqlTypeOrSelectable + TupleSize, T: Queryable<ST, DB>, DB: Backend,

Source§

const FIELD_COUNT: usize = <ST as crate::util::TupleSize>::SIZE

The number of fields that this type will consume.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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

Source§

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

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

Source§

fn vzip(self) -> V