1 stable release
| 2.1.2 | May 5, 2026 |
|---|---|
| 2.1.0 |
|
#306 in Games
Used in 3 crates
32KB
568 lines
steamid-rs
A Rust library for parsing, validating, and converting Steam IDs between different formats.
Features
- Parse Steam IDs from multiple formats:
- Steam2:
STEAM_0:0:23071901 - Steam3:
[U:1:46143802] - SteamID64:
76561198006409530
- Steam2:
- Convert between all formats seamlessly
- Validate Steam IDs
- Zero-copy parsing with comprehensive error handling
- No runtime dependencies (only
regexandthiserror)
Installation
Add this to your Cargo.toml:
[dependencies]
steamid-rs = "2.1"
The library is imported as steamid in your code (the package name is steamid-rs because steamid was already taken on crates.io).
Usage
Parsing Steam IDs
use steamid::SteamID;
// Parse from any format using .parse()
let sid: SteamID = "STEAM_0:0:23071901".parse().unwrap();
let sid: SteamID = "[U:1:46143802]".parse().unwrap();
let sid: SteamID = "76561198006409530".parse().unwrap();
// Or use TryFrom
let sid = SteamID::try_from("[U:1:46143802]").unwrap();
// From a 64-bit integer
let sid = SteamID::from(76561198006409530u64);
Creating from Account ID
use steamid::SteamID;
// Create a SteamID from an individual account ID
let sid = SteamID::from_individual_account_id(46143802);
assert!(sid.is_valid());
Converting Between Formats
use steamid::SteamID;
let sid: SteamID = "76561198006409530".parse().unwrap();
// Convert to Steam2 format
println!("{}", sid.steam2(false).unwrap()); // "STEAM_0:0:23071901"
println!("{}", sid.steam2(true).unwrap()); // "STEAM_1:0:23071901"
// Convert to Steam3 format
println!("{}", sid.steam3()); // "[U:1:46143802]"
// Get the 64-bit representation
println!("{}", sid.steam_id64()); // 76561198006409530
// Display trait uses Steam3 format
println!("{}", sid); // "[U:1:46143802]"
Validation
use steamid::SteamID;
let sid: SteamID = "[U:1:46143802]".parse().unwrap();
// Check if valid according to Steam
assert!(sid.is_valid());
// Check if it's a valid individual user account
assert!(sid.is_valid_individual());
// Check for special account types
assert!(!sid.is_group_chat());
assert!(!sid.is_lobby());
Accessing Components
use steamid::{SteamID, Universe, AccountType, Instance};
let sid: SteamID = "[U:1:46143802]".parse().unwrap();
assert_eq!(sid.universe, Universe::Public);
assert_eq!(sid.account_type, AccountType::Individual);
assert_eq!(sid.instance, Instance::Desktop);
assert_eq!(sid.account_id, 46143802);
Error Handling
use steamid::{SteamID, SteamIdError};
let result: Result<SteamID, SteamIdError> = "invalid".parse();
assert!(result.is_err());
match result {
Ok(sid) => println!("Parsed: {}", sid),
Err(e) => println!("Error: {}", e),
}
API Reference
SteamID Struct
| Method | Description |
|---|---|
new() |
Creates a new invalid SteamID |
from_individual_account_id(u32) |
Creates a SteamID for an individual user |
from_steam_id64(u64) |
Parses from a 64-bit integer |
is_valid() |
Returns whether Steam considers this ID valid |
is_valid_individual() |
Returns whether this is a valid individual user |
is_group_chat() |
Checks if this is a legacy group chat |
is_lobby() |
Checks if this is a game lobby |
steam2(bool) |
Renders in Steam2 format |
steam3() |
Renders in Steam3 format |
steam_id64() |
Returns the 64-bit representation |
Enums
Universe-Invalid,Public,Beta,Internal,DevAccountType-Invalid,Individual,Multiseat,GameServer,AnonGameServer,Pending,ContentServer,Clan,Chat,AnonUserInstance-All,Desktop,Console,Web
Constants
chat_instance_flags::CLAN- Flag for clan chat instanceschat_instance_flags::LOBBY- Flag for lobby chat instances
License
Credits
This is a Rust port of node-steamid by DoctorMcKay.
Dependencies
~2–3.5MB
~68K SLoC