diff --git a/Cargo.toml b/Cargo.toml index 0cce434..d542597 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,13 @@ async-std = { version = "1.12.0", optional = true, features = [ "attributes" ] } thiserror = "1.0.40" derive_builder = "0.12.0" +[build-dependencies] +rustc_version = "0.4.0" + [dev-dependencies] async-std = { version = "1.12.0", features = [ "attributes" ] } tokio = { version = "1.29.1", features = [ "time", "rt", "macros", "rt-multi-thread" ] } thiserror = "1.0.40" + +[package.metadata.docs.rs] +all-features = true \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..4b05b5c --- /dev/null +++ b/build.rs @@ -0,0 +1,12 @@ +use rustc_version::{version_meta, Channel}; + +fn main() { + // Set cfg flags depending on release channel + let channel = match version_meta().unwrap().channel { + Channel::Stable => "CHANNEL_STABLE", + Channel::Beta => "CHANNEL_BETA", + Channel::Nightly => "CHANNEL_NIGHTLY", + Channel::Dev => "CHANNEL_DEV", + }; + println!("cargo:rustc-cfg={}", channel) +} diff --git a/examples/async_std.rs b/examples/async_std.rs index bf58814..dd18800 100644 --- a/examples/async_std.rs +++ b/examples/async_std.rs @@ -4,7 +4,7 @@ use std::{ time::Duration, }; -use situwaition::{runtime::async_std::wait_for, runtime::AsyncWaiter, AsyncSituwaition}; +use situwaition::{runtime::async_std::wait_for, runtime::AsyncWaiter, AsyncStdAsyncSituwaition}; use thiserror::Error; #[derive(Debug, Error)] diff --git a/examples/tokio.rs b/examples/tokio.rs index 29db832..4017cfa 100644 --- a/examples/tokio.rs +++ b/examples/tokio.rs @@ -4,7 +4,7 @@ use std::{ time::Duration, }; -use situwaition::{runtime::tokio::wait_for, runtime::AsyncWaiter, AsyncSituwaition}; +use situwaition::{runtime::tokio::wait_for, runtime::AsyncWaiter, TokioAsyncSituwaition}; use thiserror::Error; #[derive(Debug, Error)] diff --git a/src/lib.rs b/src/lib.rs index 429acaa..7e4598c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,8 @@ //! }); //! } //! ``` +//! +//! The example above demonstrates the synchronous usage, but `tokio` and `async-std` and corresponding modules are available as well. use std::{result::Result, time::Duration}; @@ -105,11 +107,21 @@ pub trait SyncSituwaition: SituwaitionBase { fn exec(&mut self) -> Result>; } -/// This trait represents a "situwaition" that can be a"waited". +/// This trait represents a "situwaition" that can be a"waited", with tokio. /// note that how the waiting is done can differ by platform -#[cfg(any(feature = "tokio", feature = "async-std"))] +#[cfg(feature = "tokio")] +#[async_trait] +pub trait TokioAsyncSituwaition: SituwaitionBase { + /// Execute the situwaition, and wait until it resolves + /// or fails with a timeout + async fn exec(&mut self) -> Result>; +} + +/// This trait represents a "situwaition" that can be a"waited", with async-std. +/// note that how the waiting is done can differ by platform +#[cfg(feature = "async-std")] #[async_trait] -pub trait AsyncSituwaition: SituwaitionBase { +pub trait AsyncStdAsyncSituwaition: SituwaitionBase { /// Execute the situwaition, and wait until it resolves /// or fails with a timeout async fn exec(&mut self) -> Result>; diff --git a/src/runtime/async_std.rs b/src/runtime/async_std.rs index 2168a88..f2c08f5 100644 --- a/src/runtime/async_std.rs +++ b/src/runtime/async_std.rs @@ -1,3 +1,4 @@ +#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))] #![cfg(feature = "async-std")] use std::{error::Error, future::Future, time::Instant}; @@ -5,12 +6,12 @@ use std::{error::Error, future::Future, time::Instant}; use async_std::{future::timeout, task::sleep}; use async_trait::async_trait; -use crate::{AsyncSituwaition, SituwaitionError}; +use crate::{AsyncStdAsyncSituwaition, SituwaitionError}; use super::AsyncWaiter; #[async_trait] -impl AsyncSituwaition for AsyncWaiter +impl AsyncStdAsyncSituwaition for AsyncWaiter where F: Future> + Send, A: Fn() -> F + Send, diff --git a/src/runtime/tokio.rs b/src/runtime/tokio.rs index 2eb8a36..fe589e3 100644 --- a/src/runtime/tokio.rs +++ b/src/runtime/tokio.rs @@ -1,3 +1,4 @@ +#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))] #![cfg(feature = "tokio")] use std::{error::Error, future::Future}; @@ -5,12 +6,12 @@ use std::{error::Error, future::Future}; use async_trait::async_trait; use tokio::time::{sleep, timeout, Instant}; -use crate::{AsyncSituwaition, SituwaitionError}; +use crate::{TokioAsyncSituwaition, SituwaitionError}; use super::AsyncWaiter; #[async_trait] -impl AsyncSituwaition for AsyncWaiter +impl TokioAsyncSituwaition for AsyncWaiter where F: Future> + Send, A: Fn() -> F + Send,