#[repr(transparent)]
pub struct Id<T> { /* private fields */ }
Expand description

ID of a resource, such as the ID of a channel or user.

Markers themselves perform no logical action, and are only used to ensure that IDs of incorrect types aren’t used. Read the marker documentation for additional information.

serde

This ID deserializes from both integers and strings and serializes into a string.

Implementations

Create a new ID, panicking if the value is zero.

This is primarily useful in const contexts where you are passing a hardcoded value.

Refer to new_checked for a checked alternative to this method.

Examples
use twilight_model::id::{marker::GenericMarker, Id};

const ID: Id<GenericMarker> = Id::new(123);

println!("id: {ID}");
Panics

Panics if the value is 0.

Create a non-zero application ID without checking the value.

Equivalent to NonZeroU64::new_unchecked.

Safety

The value must not be zero.

Create a non-zero application ID, checking if the provided value is zero.

Examples
use twilight_model::id::{marker::GenericMarker, Id};

assert!(Id::<GenericMarker>::new_checked(123).is_some());
assert!(Id::<GenericMarker>::new_checked(0).is_none());

Equivalent to NonZeroU64::new.

Return the inner primitive value.

Equivalent to NonZeroU64::get.

Examples

Create an ID with a value and then confirm its inner value:

use twilight_model::id::{marker::ChannelMarker, Id};

let channel_id = Id::<ChannelMarker>::new(7);

assert_eq!(7, channel_id.get());

Return the NonZeroU64 representation of the ID.

Examples

Create an ID with a value and then confirm its nonzero value:

use std::num::NonZeroU64;
use twilight_model::id::{marker::ChannelMarker, Id};

let channel_id = Id::<ChannelMarker>::new(7);

assert_eq!(NonZeroU64::new(7).unwrap(), channel_id.into_nonzero());

Cast an ID from one type to another.

Examples

Cast a role ID to a guild ID, useful for the @everyone role:

use twilight_model::id::{marker::{GuildMarker, RoleMarker}, Id};

let role_id: Id<RoleMarker> = Id::new(1);

let guild_id: Id<GuildMarker> = role_id.cast();
assert_eq!(1, guild_id.get());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more