Trait Id

Source
pub trait Id:
    Copy
    + Clone
    + PartialOrd
    + Ord
    + PartialEq
    + Eq
    + Hash
    + Debug {
    type Ty: Copy + Clone + Default + Debug + Display + Ord + PartialOrd + Eq + PartialEq + Hash + ToU64 + From<u8> + Add<Output = Self::Ty> + AddAssign<Self::Ty> + Sub<Output = Self::Ty> + SubAssign<Self::Ty> + Mul<Output = Self::Ty> + MulAssign<Self::Ty> + Div<Output = Self::Ty> + DivAssign<Self::Ty> + BitOr<Output = Self::Ty> + BitOrAssign<Self::Ty> + BitAnd<Output = Self::Ty> + BitAndAssign<Self::Ty> + BitXor<Output = Self::Ty> + BitXorAssign<Self::Ty> + Not<Output = Self::Ty> + Shl<u8, Output = Self::Ty> + Shr<u8, Output = Self::Ty> + Shl<u32, Output = Self::Ty> + Shr<u32, Output = Self::Ty> + Shl<u64, Output = Self::Ty> + Shr<u64, Output = Self::Ty> + Shl<u128, Output = Self::Ty> + Shr<u128, Output = Self::Ty> + Shl<usize, Output = Self::Ty> + Shr<usize, Output = Self::Ty> + ShlAssign<Self::Ty> + ShrAssign<Self::Ty>;

    const ZERO: Self::Ty;
    const ONE: Self::Ty;

    // Required methods
    fn to_raw(&self) -> Self::Ty;
    fn from_raw(raw: Self::Ty) -> Self;
}
Expand description

A trait for types that wrap a primitive scalar identifier.

This is used to abstract over the raw scalar type behind an ID (e.g., u64, u128).

Types implementing Id must define a scalar type Ty and provide conversion to/from this raw representation.

Required Associated Constants§

Source

const ZERO: Self::Ty

Zero value (used for resetting the sequence)

Source

const ONE: Self::Ty

One value (used for incrementing the sequence)

Required Associated Types§

Source

type Ty: Copy + Clone + Default + Debug + Display + Ord + PartialOrd + Eq + PartialEq + Hash + ToU64 + From<u8> + Add<Output = Self::Ty> + AddAssign<Self::Ty> + Sub<Output = Self::Ty> + SubAssign<Self::Ty> + Mul<Output = Self::Ty> + MulAssign<Self::Ty> + Div<Output = Self::Ty> + DivAssign<Self::Ty> + BitOr<Output = Self::Ty> + BitOrAssign<Self::Ty> + BitAnd<Output = Self::Ty> + BitAndAssign<Self::Ty> + BitXor<Output = Self::Ty> + BitXorAssign<Self::Ty> + Not<Output = Self::Ty> + Shl<u8, Output = Self::Ty> + Shr<u8, Output = Self::Ty> + Shl<u32, Output = Self::Ty> + Shr<u32, Output = Self::Ty> + Shl<u64, Output = Self::Ty> + Shr<u64, Output = Self::Ty> + Shl<u128, Output = Self::Ty> + Shr<u128, Output = Self::Ty> + Shl<usize, Output = Self::Ty> + Shr<usize, Output = Self::Ty> + ShlAssign<Self::Ty> + ShrAssign<Self::Ty>

Scalar type for all bit fields (typically u64 or u128)

Required Methods§

Source

fn to_raw(&self) -> Self::Ty

Converts this type into its raw type representation

Source

fn from_raw(raw: Self::Ty) -> Self

Converts a raw type into this type

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Id for SnowflakeDiscordId

Source§

const ZERO: u64 = 0u64

Source§

const ONE: u64 = 1u64

Source§

type Ty = u64

Source§

impl Id for SnowflakeInstagramId

Source§

const ZERO: u64 = 0u64

Source§

const ONE: u64 = 1u64

Source§

type Ty = u64

Source§

impl Id for SnowflakeMastodonId

Source§

const ZERO: u64 = 0u64

Source§

const ONE: u64 = 1u64

Source§

type Ty = u64

Source§

impl Id for SnowflakeTwitterId

Source§

const ZERO: u64 = 0u64

Source§

const ONE: u64 = 1u64

Source§

type Ty = u64

Source§

impl Id for ULID

Source§

const ZERO: u128 = 0u128

Source§

const ONE: u128 = 1u128

Source§

type Ty = u128