Skip to main content

TSIDDatabaseID

Struct TSIDDatabaseID 

Source
pub struct TSIDDatabaseID<Resource: TSIDResource> { /* private fields */ }
Expand description

Represents a prefixed, type-safe, resource-specific ID in your database. The resource is defined by Resource: when deserializing, that resource must be matched when reading the prefix. When serializing, that resource will be used to create the prefix.

Internally, this stores a TSID, which is actually a u64. In your database, you should probably store this u64 instead of the base32-encoded prefixed string. The numbers are time-ordered so you can sort your database with great performance.

Implementations§

Source§

impl<Resource: TSIDResource> TSIDDatabaseID<Resource>

Source

pub fn from_raw_number(number: u64) -> Self

Parse a number (e.g. from your database) into a TSID. As long as it fits into a u64, it will be a valid ID, so this can’t error.

Source

pub fn from_integer(number: i64) -> Self

Source

pub fn random() -> Self

Creates a new, random TSID.

Source

pub fn to_raw_number(&self) -> u64

Returns the u64 value of the TSID stored internally. Use this to get a value you can store in your database.

Source

pub fn into_unknown(&self) -> TSIDDatabaseID<IDUnknown>

Methods from Deref<Target = TSID>§

Source

pub fn number(&self) -> u64

Returns numeric representation of TSID

Source

pub fn random_part(&self) -> u64

Trait Implementations§

Source§

impl<Resource: Clone + TSIDResource> Clone for TSIDDatabaseID<Resource>

Source§

fn clone(&self) -> TSIDDatabaseID<Resource>

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<Resource: Debug + TSIDResource> Debug for TSIDDatabaseID<Resource>

Source§

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

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

impl<Resource: TSIDResource> Deref for TSIDDatabaseID<Resource>

Source§

type Target = TSID

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'de, Resource: TSIDResource> Deserialize<'de> for TSIDDatabaseID<Resource>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Resource: TSIDResource> Display for TSIDDatabaseID<Resource>

Source§

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

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

impl<Resource: TSIDResource> From<TSID> for TSIDDatabaseID<Resource>

Source§

fn from(value: TSID) -> Self

Converts to this type from the input type.
Source§

impl<Resource: TSIDResource> FromStr for TSIDDatabaseID<Resource>

Source§

fn from_str(v: &str) -> Result<TSIDDatabaseID<Resource>, Error>

Attempts to parse a string into a TSIDDatabaseID matching the prefix of the specified resource. If the string does not contain a prefix, or it contains the wrong one, an error will be returned instead.

If the resource does not require a prefix, any string is accepted, as long as it is a valid base32-encoded TSID.

Source§

type Err = Error

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

impl<Resource: Hash + TSIDResource> Hash for TSIDDatabaseID<Resource>

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<Resource: PartialEq + TSIDResource> PartialEq for TSIDDatabaseID<Resource>

Source§

fn eq(&self, other: &TSIDDatabaseID<Resource>) -> 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<Resource: TSIDResource> Serialize for TSIDDatabaseID<Resource>

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<Resource: Copy + TSIDResource> Copy for TSIDDatabaseID<Resource>

Source§

impl<Resource: Eq + TSIDResource> Eq for TSIDDatabaseID<Resource>

Source§

impl<Resource: TSIDResource> StructuralPartialEq for TSIDDatabaseID<Resource>

Auto Trait Implementations§

§

impl<Resource> Freeze for TSIDDatabaseID<Resource>

§

impl<Resource> RefUnwindSafe for TSIDDatabaseID<Resource>
where Resource: RefUnwindSafe,

§

impl<Resource> Send for TSIDDatabaseID<Resource>

§

impl<Resource> Sync for TSIDDatabaseID<Resource>
where Resource: Sync,

§

impl<Resource> Unpin for TSIDDatabaseID<Resource>
where Resource: Unpin,

§

impl<Resource> UnwindSafe for TSIDDatabaseID<Resource>
where Resource: 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,