Skip to main content

compio_compat/sys/
mod.rs

1use std::{io, ops::Deref, time::Duration};
2
3use compio_runtime::Runtime;
4use mod_use::mod_use;
5
6cfg_if::cfg_if! {
7    if #[cfg(windows)] {
8        mod_use![windows];
9    } else if #[cfg(unix)] {
10        mod_use![unix];
11    } else {
12        compile_error!("Unsupported platform");
13    }
14}
15
16/// Adapter trait for different runtimes.
17#[allow(async_fn_in_trait)]
18pub trait Adapter: Sized + Deref<Target = Runtime> {
19    /// Creates a new adapter with the given runtime.
20    fn new(runtime: Runtime) -> io::Result<Self>;
21
22    /// Waits for the runtime to be ready, with an optional timeout.
23    async fn wait(&self, timeout: Option<Duration>) -> io::Result<()>;
24
25    /// Clears the runtime's state after waiting.
26    fn clear(&self) -> io::Result<()>;
27}