Struct twilight_model::id::Id
source · [−]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());
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
Deserialize this value from the given Serde deserializer. Read more
Performs the conversion.
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
Auto Trait Implementations
impl<T> RefUnwindSafe for Id<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Id<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
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