Enum steamidfx::id::Id[][src]

pub enum Id {
    Id64(Id64),
    Id32(Id32),
    Id3(Id3),
}

https://developer.valvesoftware.com/wiki/SteamID Holds a steam id in various formats.

Example

use std::convert::TryFrom;

let steam_id_64 = steamidfx::id::Id64(76561197983318796);
let steam_id_3 = steamidfx::id::Id3("U:1:23053068".to_owned());
assert_eq!(
    steamidfx::id::Id32::try_from(steam_id_3.clone()).unwrap(),
    steamidfx::id::Id32("STEAM_0:0:11526534".to_owned())
);
assert_eq!(
    steamidfx::id::Id64::try_from(steam_id_3).unwrap(),
    steamidfx::id::Id64(76561197983318796)
);
assert_eq!(
    steamidfx::id::Id32::try_from(steam_id_64).unwrap(),
    steamidfx::id::Id32("STEAM_0:0:11526534".to_owned())
);

// The most preferred way to construct Ids is using the fallible `TryFrom`.
// This will make sure that the constructed `ID`s are correct as some of
// the fields of it are required to be of some certain ranges of values.
use std::str::FromStr;

let id_64 = steamidfx::id::Id::from_str("76561197983318796").unwrap();
let id_64_2 = steamidfx::id::Id::try_from(76561197983318796).unwrap();
let id_32 = steamidfx::id::Id::from_str("STEAM_0:0:11526534").unwrap();
let id_3 = steamidfx::id::Id::from_str("U:1:23053068").unwrap();
// This way you'll make sure after unpacking the `Result` that the value is correct
// at least, according to the specification.

Variants

Id64(Id64)

Steam ID in a single integer format (SteamID64). Example: 7656119xxxxxxxxxx.

Id32(Id32)

Steam ID 32 in the default format, starting with STEAM_0. Example: STEAM_0:X:XXXXXXXX.

Id3(Id3)

Steam ID in the format called “Steam ID 3”. Example: U:1:xxxxxxxx.

Implementations

impl Id[src]

pub fn id64(&self) -> Result<Id64>[src]

Converts (if needed) the current id format into id64.

Errors

Throws crate::error::Error if it was impossible to extract the steam id 64.

pub fn id32(&self) -> Result<Id32>[src]

Converts (if needed) the current id format into id32.

Errors

Throws crate::error::Error if it was impossible to extract the steam id 32.

pub fn into_id64(self) -> Result<Id>[src]

Consumes the object and converts it into a steam id in the id64 format.

Errors

Throws crate::error::Error if it was impossible to extract the steam id 64.

pub fn into_id32(self) -> Result<Id>[src]

Consumes the object and converts it into a steam id in the id32 format.

Errors

Throws crate::error::Error if it was impossible to extract the steam id 32.

pub fn is_same(&self, other: &Id) -> Result<bool>[src]

Attempts to compare two ids. Returns true when they are representing the same values, even using different formats. The conventional Eq and PartialEq traits derived will be checking the enum variants and strings inside, which is sometimes not what we want. Sometimes we just want to say that these two Id objects represent the same person, or an entity of valve. For that, we aren’t interested in the format of the ID, but rather in the data it provides.

Errors

Returns an error when it is impossible to convert both ids to a single format: id64. This format is used as it is the most commonly used one, and provides the most information possible. Hence, all the ID formats should ideally be convertible to it just fine, but we are still performing all the checks to be a bit more cautious about it.

Examples

use std::str::FromStr;
use std::convert::TryFrom;

let id_64 = steamidfx::id::Id::try_from(76561197983318796).unwrap();
let id_32 = steamidfx::id::Id::from_str("STEAM_0:0:11526534").unwrap();
let id_3 = steamidfx::id::Id::from_str("U:1:23053068").unwrap();
assert!(id_3.is_same(&id_32).unwrap());
assert!(id_32.is_same(&id_64).unwrap());

Trait Implementations

impl Clone for Id[src]

impl Debug for Id[src]

impl<'de> Deserialize<'de> for Id[src]

impl Display for Id[src]

impl Eq for Id[src]

impl FromStr for Id[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Id[src]

impl Ord for Id[src]

impl PartialEq<Id> for Id[src]

impl PartialOrd<Id> for Id[src]

impl Serialize for Id[src]

impl StructuralEq for Id[src]

impl StructuralPartialEq for Id[src]

impl TryFrom<u64> for Id[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Id

impl Send for Id

impl Sync for Id

impl Unpin for Id

impl UnwindSafe for Id

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.