chrome_for_testing/api/
platform.rs1use serde::Deserialize;
2use std::env::consts;
3use std::fmt::{Display, Formatter};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
6pub enum Platform {
7 #[serde(rename = "linux64")]
8 Linux64,
9 #[serde(rename = "mac-arm64")]
10 MacArm64,
11 #[serde(rename = "mac-x64")]
12 MacX64,
13 #[serde(rename = "win32")]
14 Win32,
15 #[serde(rename = "win64")]
16 Win64,
17}
18
19impl Display for Platform {
20 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21 f.write_str(match self {
22 Platform::Linux64 => "linux64",
23 Platform::MacArm64 => "mac-arm64",
24 Platform::MacX64 => "mac-x64",
25 Platform::Win32 => "win32",
26 Platform::Win64 => "win64",
27 })
28 }
29}
30
31impl Platform {
32 pub fn detect() -> Platform {
34 match consts::OS {
35 "windows" => match consts::ARCH {
36 "x86" => Platform::Win32,
37 "x86_64" => Platform::Win64,
38 _ => panic!("Unsupported architecture"),
39 },
40 "linux" => match consts::ARCH {
41 "x86_64" => Platform::Linux64,
42 _ => panic!("Unsupported architecture"),
43 },
44 "macos" => match consts::ARCH {
45 "x86_64" => Platform::MacX64,
46 "arm" | "aarch64" => Platform::MacArm64,
47 _ => panic!("Unsupported architecture"),
48 },
49 _ => panic!("Unsupported OS"),
50 }
51 }
52
53 pub fn chrome_binary_name(self) -> &'static str {
54 match self {
55 Platform::Linux64 | Platform::MacX64 => "chrome",
56 Platform::MacArm64 => "Google Chrome for Testing.app",
57 Platform::Win32 | Platform::Win64 => "chrome.exe",
58 }
59 }
60
61 pub fn chromedriver_binary_name(self) -> &'static str {
62 match self {
63 Platform::Linux64 | Platform::MacX64 | Platform::MacArm64 => "chromedriver",
64 Platform::Win32 | Platform::Win64 => "chromedriver.exe",
65 }
66 }
67}