diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-12-27 14:38:36 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-01-08 11:34:07 +0100 |
| commit | 857febc80eaff8f5efc4239b2c625fcfbee78999 (patch) | |
| tree | ce29bea94421884ff91021efa8b43d21088edf3c /test/test-rpc/src/meta.rs | |
| parent | aca939c260f718e3806a67b0a0703a33d4c8157f (diff) | |
| download | mullvadvpn-857febc80eaff8f5efc4239b2c625fcfbee78999.tar.xz mullvadvpn-857febc80eaff8f5efc4239b2c625fcfbee78999.zip | |
Add 'target_os' attribute to test macro
Diffstat (limited to 'test/test-rpc/src/meta.rs')
| -rw-r--r-- | test/test-rpc/src/meta.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/test/test-rpc/src/meta.rs b/test/test-rpc/src/meta.rs index 67c87738e0..958733b9be 100644 --- a/test/test-rpc/src/meta.rs +++ b/test/test-rpc/src/meta.rs @@ -1,12 +1,26 @@ use serde::{Deserialize, Serialize}; +use std::str::FromStr; -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)] pub enum Os { Linux, Macos, Windows, } +impl FromStr for Os { + type Err = Box<dyn std::error::Error>; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "linux" => Ok(Os::Linux), + "macos" => Ok(Os::Macos), + "windows" => Ok(Os::Windows), + other => Err(format!("unknown os {other}").into()), + } + } +} + impl std::fmt::Display for Os { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -16,12 +30,3 @@ impl std::fmt::Display for Os { } } } - -#[cfg(target_os = "linux")] -pub const CURRENT_OS: Os = Os::Linux; - -#[cfg(target_os = "windows")] -pub const CURRENT_OS: Os = Os::Windows; - -#[cfg(target_os = "macos")] -pub const CURRENT_OS: Os = Os::Macos; |
