valorant_api/enums/
platform.rs1use std::fmt::Display;
2use std::str::FromStr;
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct ClientPlatform {
9 platform_type: String,
10 #[serde(rename = "platformOS")]
11 platform_os: String,
12 #[serde(rename = "platformOSVersion")]
13 platform_os_version: String,
14 platform_chipset: String,
15}
16
17#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
18pub enum Platform {
19 #[default]
20 PC,
21 XBOX,
22 PlayStation,
23}
24
25impl Platform {
26 pub(crate) fn get_client_version(&self) -> ClientPlatform {
27 ClientPlatform {
28 platform_type: self.get_platform_type().to_string(),
29 platform_os: self.get_platform_os().to_string(),
30 platform_os_version: self.get_platform_os_version().to_string(),
31 platform_chipset: self.get_platform_chipset().to_string(),
32 }
33 }
34
35 fn get_platform_type(&self) -> &str {
36 match self {
37 Platform::PC => "PC",
38 Platform::XBOX => "xbox",
39 Platform::PlayStation => "playstation",
40 }
41 }
42
43 fn get_platform_os(&self) -> &str {
44 match self {
45 Platform::PC => "Windows",
46 Platform::XBOX => "Xbox",
47 Platform::PlayStation => "PlayStation",
48 }
49 }
50
51 fn get_platform_os_version(&self) -> &str {
52 match self {
53 Platform::PC => "10.0.19042.1.256.64bit",
54 Platform::XBOX => "10.0.19042.1.256.64bit",
55 Platform::PlayStation => "10.0.19042.1.256.64bit",
56 }
57 }
58
59 fn get_platform_chipset(&self) -> &str {
60 match self {
61 Platform::PC => "Unknown",
62 Platform::XBOX => "Unknown",
63 Platform::PlayStation => "Unknown",
64 }
65 }
66}
67
68impl FromStr for Platform {
69 type Err = ();
70
71 fn from_str(s: &str) -> Result<Self, Self::Err> {
72 match s.to_lowercase().as_str() {
73 "pc" => Ok(Platform::PC),
74 "xbox" => Ok(Platform::XBOX),
75 "playstation" => Ok(Platform::PlayStation),
76 _ => Err(()),
77 }
78 }
79}
80
81impl Display for Platform {
82 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83 match self {
84 Platform::PC => write!(f, "PC"),
85 Platform::XBOX => write!(f, "XBOX"),
86 Platform::PlayStation => write!(f, "PlayStation"),
87 }
88 }
89}