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