1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
// System
/// A trait for interacting with the system.
///
/// [Example](https://github.com/leroyguillaume/mockable/tree/main/examples/sys.rs).
pub trait System: Send + Sync {
/// Open a URL in the default browser.
///
/// **This is supported on `feature=browser` only.**
#[cfg(feature = "browser")]
fn open_url(&self, url: &str) -> std::io::Result<()>;
}
// DefaultSystem
/// Default implementation of [`System`](trait.System.html).
///
/// [Example](https://github.com/leroyguillaume/mockable/tree/main/examples/sys.rs).
pub struct DefaultSystem;
impl System for DefaultSystem {
#[cfg(feature = "browser")]
fn open_url(&self, url: &str) -> std::io::Result<()> {
open::that(url)
}
}
// MockSystem
#[cfg(feature = "mock")]
mockall::mock! {
/// `mockall` implementation of [`System`](trait.System.html).
///
/// **This is supported on `feature=mock` only.**
///
/// [Example](https://github.com/leroyguillaume/mockable/tree/main/examples/sys.rs).
pub System {}
impl System for System {
#[cfg(feature = "browser")]
fn open_url(&self, url: &str) -> std::io::Result<()>;
}
}