Skip to content

Commit 2075b7d

Browse files
committed
fingerprint_mod
1 parent 89101b1 commit 2075b7d

File tree

7 files changed

+72
-94
lines changed

7 files changed

+72
-94
lines changed

lib/bencher_context/src/client/platform/target_os/linux.rs renamed to lib/bencher_context/src/client/platform/fingerprint/linux.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use std::fs;
22

33
use uuid::Uuid;
44

5-
use crate::client::platform::OperatingSystem;
6-
75
const HEX_BASE: u32 = 16;
86

97
impl crate::Fingerprint {
@@ -20,10 +18,3 @@ fn parse_machine_id(path: &str) -> Option<Uuid> {
2018
.and_then(|id| u128::from_str_radix(id.trim(), HEX_BASE).ok())
2119
.map(Uuid::from_u128)
2220
}
23-
24-
impl OperatingSystem {
25-
#[allow(clippy::unnecessary_wraps)]
26-
pub fn current() -> Option<Self> {
27-
Some(Self::Linux)
28-
}
29-
}

lib/bencher_context/src/client/platform/target_os/macos.rs renamed to lib/bencher_context/src/client/platform/fingerprint/macos.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use std::process::Command;
22

33
use uuid::Uuid;
44

5-
use crate::client::platform::OperatingSystem;
6-
75
impl crate::Fingerprint {
86
pub fn current() -> Option<Self> {
97
Command::new("ioreg")
@@ -26,10 +24,3 @@ impl crate::Fingerprint {
2624
.map(Self)
2725
}
2826
}
29-
30-
impl OperatingSystem {
31-
#[allow(clippy::unnecessary_wraps)]
32-
pub fn current() -> Option<Self> {
33-
Some(Self::MacOS)
34-
}
35-
}

lib/bencher_context/src/client/platform/base36.rs renamed to lib/bencher_context/src/client/platform/fingerprint/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1+
use std::fmt;
2+
13
use bencher_valid::BASE_36;
24
use uuid::Uuid;
35

4-
pub fn encode_uuid(uuid: Uuid) -> String {
6+
#[cfg(target_os = "linux")]
7+
mod linux;
8+
#[cfg(target_os = "macos")]
9+
mod macos;
10+
#[cfg(target_os = "windows")]
11+
mod windows;
12+
13+
#[derive(Debug, Clone, Copy)]
14+
pub struct Fingerprint(Uuid);
15+
16+
impl fmt::Display for Fingerprint {
17+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18+
write!(f, "{}", encode_uuid(self.0))
19+
}
20+
}
21+
22+
#[cfg(all(
23+
not(target_os = "linux"),
24+
not(target_os = "macos"),
25+
not(target_os = "windows")
26+
))]
27+
impl Fingerprint {
28+
#[allow(clippy::unnecessary_wraps)]
29+
pub fn current() -> Option<Self> {
30+
None
31+
}
32+
}
33+
34+
fn encode_uuid(uuid: Uuid) -> String {
535
const ENCODED_LEN: usize = 13;
636

737
let base = BASE_36.len() as u64;

lib/bencher_context/src/client/platform/target_os/windows.rs renamed to lib/bencher_context/src/client/platform/fingerprint/windows.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use windows::{
77
Win32::System::Registry::{RegGetValueW, HKEY_LOCAL_MACHINE, RRF_RT_ANY},
88
};
99

10-
use crate::client::platform::OperatingSystem;
11-
1210
impl crate::Fingerprint {
1311
pub fn current() -> Option<Self> {
1412
serial_number().or_else(digital_product_id).map(Self)
@@ -60,10 +58,3 @@ fn digital_product_id() -> Option<Uuid> {
6058
.fold(0u128, |acc, byte| (acc << 8) | u128::from(byte));
6159
Some(Uuid::from_u128(digital_product_id))
6260
}
63-
64-
impl OperatingSystem {
65-
#[allow(clippy::unnecessary_wraps)]
66-
pub fn current() -> Option<Self> {
67-
Some(Self::Windows)
68-
}
69-
}
Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,5 @@
1-
use std::fmt;
1+
mod fingerprint;
2+
mod operating_system;
23

3-
use uuid::Uuid;
4-
5-
mod base36;
6-
mod target_os;
7-
8-
#[derive(Debug, Clone, Copy)]
9-
pub struct Fingerprint(Uuid);
10-
11-
impl fmt::Display for Fingerprint {
12-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13-
write!(f, "{}", base36::encode_uuid(self.0))
14-
}
15-
}
16-
17-
#[cfg(all(
18-
not(target_os = "linux"),
19-
not(target_os = "macos"),
20-
not(target_os = "windows")
21-
))]
22-
impl Fingerprint {
23-
#[allow(clippy::unnecessary_wraps)]
24-
pub fn current() -> Option<Self> {
25-
None
26-
}
27-
}
28-
29-
#[allow(dead_code)]
30-
#[derive(Debug, Clone, Copy)]
31-
pub enum OperatingSystem {
32-
Linux,
33-
MacOS,
34-
Windows,
35-
}
36-
37-
impl fmt::Display for OperatingSystem {
38-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39-
write!(
40-
f,
41-
"{}",
42-
match self {
43-
OperatingSystem::Linux => "Linux",
44-
OperatingSystem::MacOS => "macOS",
45-
OperatingSystem::Windows => "Windows",
46-
}
47-
)
48-
}
49-
}
50-
51-
#[cfg(all(
52-
not(target_os = "linux"),
53-
not(target_os = "macos"),
54-
not(target_os = "windows")
55-
))]
56-
impl OperatingSystem {
57-
#[allow(clippy::unnecessary_wraps)]
58-
pub fn current() -> Option<Self> {
59-
None
60-
}
61-
}
4+
pub use fingerprint::Fingerprint;
5+
pub use operating_system::OperatingSystem;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::fmt;
2+
3+
#[allow(dead_code)]
4+
#[derive(Debug, Clone, Copy)]
5+
pub enum OperatingSystem {
6+
Linux,
7+
MacOS,
8+
Windows,
9+
}
10+
11+
impl fmt::Display for OperatingSystem {
12+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13+
write!(
14+
f,
15+
"{}",
16+
match self {
17+
OperatingSystem::Linux => "Linux",
18+
OperatingSystem::MacOS => "macOS",
19+
OperatingSystem::Windows => "Windows",
20+
}
21+
)
22+
}
23+
}
24+
25+
impl OperatingSystem {
26+
pub fn current() -> Option<Self> {
27+
if cfg!(target_os = "linux") {
28+
Some(Self::Linux)
29+
} else if cfg!(target_os = "macos") {
30+
Some(Self::MacOS)
31+
} else if cfg!(target_os = "windows") {
32+
Some(Self::Windows)
33+
} else {
34+
None
35+
}
36+
}
37+
}

lib/bencher_context/src/client/platform/target_os/mod.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)