Enum uuid_mc::PlayerUuid
source · pub enum PlayerUuid {
Online(OnlineUuid),
Offline(OfflineUuid),
}Expand description
An enum that can represent both kinds of UUIDs.
Variants§
Online(OnlineUuid)
Offline(OfflineUuid)
Implementations§
source§impl PlayerUuid
impl PlayerUuid
sourcepub fn new_with_online_username(username: &str) -> Result<Self, Error>
pub fn new_with_online_username(username: &str) -> Result<Self, Error>
Creates a new instance using the username of an online player, by polling the Mojang API.
Errors
If there is no user that corresponds to the provided username, an Error::InvalidUsername is returned.
Otherwise, an Error::Transport can be returned in case of network failure.
Examples
To fetch the UUID of an online user:
use uuid::Uuid;
use uuid_mc::PlayerUuid;
let uuid = PlayerUuid::new_with_online_username("Notch")?;
let uuid = uuid.as_uuid();
let expected = Uuid::try_parse("069a79f4-44e9-4726-a5be-fca90e38aaf5")?;
assert_eq!(uuid, &expected);sourcepub fn new_with_offline_username(username: &str) -> Self
pub fn new_with_offline_username(username: &str) -> Self
Creates a new instance using the username of an offline player.
Examples
To fetch the UUID of an offline user:
use uuid::Uuid;
use uuid_mc::PlayerUuid;
let uuid = PlayerUuid::new_with_offline_username("boolean_coercion");
let uuid = uuid.as_uuid();
let expected = Uuid::try_parse("db62bdfb-eddc-3acc-a14e-c703aba52549")?;
assert_eq!(uuid, &expected);sourcepub fn new_with_uuid(uuid: Uuid) -> Result<Self, Error>
pub fn new_with_uuid(uuid: Uuid) -> Result<Self, Error>
Creates a new instance using an already existing Uuid.
Errors
In case the provided Uuid is neither offline (v3) or online (v4), an Error::InvalidUuid is returned.
Examples
To test whether a given Uuid is of the offline or online format:
use uuid::Uuid;
use uuid_mc::PlayerUuid;
let uuid_offline = Uuid::try_parse("db62bdfb-eddc-3acc-a14e-c703aba52549")?;
let uuid_online = Uuid::try_parse("61699b2e-d327-4a01-9f1e-0ea8c3f06bc6")?;
let player_uuid_offline = PlayerUuid::new_with_uuid(uuid_offline)?;
let player_uuid_online = PlayerUuid::new_with_uuid(uuid_online)?;
assert!(matches!(player_uuid_offline, PlayerUuid::Offline(_)));
assert!(matches!(player_uuid_online, PlayerUuid::Online(_)));sourcepub fn as_bytes(&self) -> &[u8; 16]
pub fn as_bytes(&self) -> &[u8; 16]
Returns the inner UUID, as a byte array. This is just a convenience function around self.as_uuid().as_bytes().
sourcepub fn unwrap_offline(self) -> OfflineUuid
pub fn unwrap_offline(self) -> OfflineUuid
Similar to Result::unwrap, this function returns the inner OfflineUuid.
Panics
If the inner UUID is not an offline one.
sourcepub fn unwrap_online(self) -> OnlineUuid
pub fn unwrap_online(self) -> OnlineUuid
Similar to Result::unwrap, this function returns the inner OnlineUuid.
Panics
If the inner UUID is not an online one.
Trait Implementations§
source§impl Clone for PlayerUuid
impl Clone for PlayerUuid
source§fn clone(&self) -> PlayerUuid
fn clone(&self) -> PlayerUuid
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for PlayerUuid
impl Debug for PlayerUuid
source§impl Hash for PlayerUuid
impl Hash for PlayerUuid
source§impl Ord for PlayerUuid
impl Ord for PlayerUuid
source§fn cmp(&self, other: &PlayerUuid) -> Ordering
fn cmp(&self, other: &PlayerUuid) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq<PlayerUuid> for PlayerUuid
impl PartialEq<PlayerUuid> for PlayerUuid
source§fn eq(&self, other: &PlayerUuid) -> bool
fn eq(&self, other: &PlayerUuid) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd<PlayerUuid> for PlayerUuid
impl PartialOrd<PlayerUuid> for PlayerUuid
source§fn partial_cmp(&self, other: &PlayerUuid) -> Option<Ordering>
fn partial_cmp(&self, other: &PlayerUuid) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more