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§

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

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

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(_)));

Returns the inner Uuid.

Returns the inner UUID, as a byte array. This is just a convenience function around self.as_uuid().as_bytes().

Similar to Result::unwrap, this function returns the inner OfflineUuid.

Panics

If the inner UUID is not an offline one.

Similar to Result::unwrap, this function returns the inner OnlineUuid.

Panics

If the inner UUID is not an online one.

Returns the contained OfflineUuid if it is present, or None otherwise.

Returns the contained OnlineUuid if it is present, or None otherwise.

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
Converts to this type from the input type.
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 ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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.

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.

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