steamid-rs 2.1.2

A SteamID library for parsing, validating, and converting Steam IDs between Steam2, Steam3, and SteamID64 formats.
Documentation
//! Enums and constants for SteamID components.

/// Steam universe types.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
#[repr(u8)]
pub enum Universe {
    #[default]
    Invalid = 0,
    Public = 1,
    Beta = 2,
    Internal = 3,
    Dev = 4,
}

impl Universe {
    /// Convert a numeric value to a Universe.
    pub fn from_u8(value: u8) -> Self {
        match value {
            1 => Universe::Public,
            2 => Universe::Beta,
            3 => Universe::Internal,
            4 => Universe::Dev,
            _ => Universe::Invalid,
        }
    }
}

/// Steam account types.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
#[repr(u8)]
pub enum AccountType {
    #[default]
    Invalid = 0,
    Individual = 1,
    Multiseat = 2,
    GameServer = 3,
    AnonGameServer = 4,
    Pending = 5,
    ContentServer = 6,
    Clan = 7,
    Chat = 8,
    P2PSuperSeeder = 9,
    AnonUser = 10,
}

impl AccountType {
    /// Convert a numeric value to an AccountType.
    pub fn from_u8(value: u8) -> Self {
        match value {
            1 => AccountType::Individual,
            2 => AccountType::Multiseat,
            3 => AccountType::GameServer,
            4 => AccountType::AnonGameServer,
            5 => AccountType::Pending,
            6 => AccountType::ContentServer,
            7 => AccountType::Clan,
            8 => AccountType::Chat,
            9 => AccountType::P2PSuperSeeder,
            10 => AccountType::AnonUser,
            _ => AccountType::Invalid,
        }
    }

    /// Get the character representation of this account type for Steam3 format.
    pub fn to_char(self) -> char {
        match self {
            AccountType::Invalid => 'I',
            AccountType::Individual => 'U',
            AccountType::Multiseat => 'M',
            AccountType::GameServer => 'G',
            AccountType::AnonGameServer => 'A',
            AccountType::Pending => 'P',
            AccountType::ContentServer => 'C',
            AccountType::Clan => 'g',
            AccountType::Chat => 'T',
            AccountType::P2PSuperSeeder => 'i', // Not typically used
            AccountType::AnonUser => 'a',
        }
    }

    /// Get the AccountType from a character in Steam3 format.
    pub fn from_char(c: char) -> Self {
        match c {
            'I' => AccountType::Invalid,
            'U' => AccountType::Individual,
            'M' => AccountType::Multiseat,
            'G' => AccountType::GameServer,
            'A' => AccountType::AnonGameServer,
            'P' => AccountType::Pending,
            'C' => AccountType::ContentServer,
            'g' => AccountType::Clan,
            'T' => AccountType::Chat,
            'a' => AccountType::AnonUser,
            _ => AccountType::Invalid,
        }
    }
}

/// Named instance values.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Instance {
    All = 0,
    Desktop = 1,
    Console = 2,
    Web = 4,
}

/// Bit masks and constants for SteamID manipulation.
pub mod masks {
    /// Mask to extract the account ID from a 64-bit SteamID.
    pub const ACCOUNT_ID_MASK: u64 = 0xFFFFFFFF;
    /// Mask to extract the instance from the upper 32 bits of a 64-bit SteamID.
    pub const ACCOUNT_INSTANCE_MASK: u32 = 0x000FFFFF;
}

/// Chat instance flags for identifying chat room types.
pub mod chat_instance_flags {
    use super::masks::ACCOUNT_INSTANCE_MASK;

    /// Flag indicating a group chat (clan chat).
    pub const CLAN: u32 = (ACCOUNT_INSTANCE_MASK + 1) >> 1; // 0x80000
    /// Flag indicating a lobby.
    pub const LOBBY: u32 = (ACCOUNT_INSTANCE_MASK + 1) >> 2; // 0x40000
    /// Flag indicating a matchmaking lobby.
    pub const MMS_LOBBY: u32 = (ACCOUNT_INSTANCE_MASK + 1) >> 3; // 0x20000
}