Skip to main content

hotl_platform/
lib.rs

1//! Platform seams (rust-implementation §Workspace layout).
2//!
3//! M0 carries only what M0 needs: `Clock` and `SecretStore`. Fs/Exec/Http
4//! traits join when the browser milestone makes indirection pay for itself;
5//! until then native crates use std/tokio/reqwest directly behind their own
6//! crate boundaries (the seam is the crate, not yet a trait).
7
8use std::time::{SystemTime, UNIX_EPOCH};
9
10pub trait Clock: Send + Sync {
11    fn now_ms(&self) -> u64;
12}
13
14#[derive(Debug, Clone, Copy, Default)]
15pub struct SystemClock;
16
17impl Clock for SystemClock {
18    fn now_ms(&self) -> u64 {
19        SystemTime::now()
20            .duration_since(UNIX_EPOCH)
21            .map(|d| d.as_millis() as u64)
22            .unwrap_or(0)
23    }
24}
25
26/// Resolution order: env var → SecretStore → prompt.
27/// M0 ships the env implementation; Keychain/secret-service land at MD.
28pub trait SecretStore: Send + Sync {
29    fn get(&self, name: &str) -> Option<String>;
30}
31
32#[derive(Debug, Clone, Copy, Default)]
33pub struct EnvSecrets;
34
35impl SecretStore for EnvSecrets {
36    fn get(&self, name: &str) -> Option<String> {
37        std::env::var(name).ok().filter(|v| !v.is_empty())
38    }
39}