Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): add doc_cfg for feature-specific items #8

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion examples/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
18 changes: 15 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -105,11 +107,21 @@ pub trait SyncSituwaition: SituwaitionBase {
fn exec(&mut self) -> Result<Self::Result, SituwaitionError<Self::Error>>;
}

/// 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<Self::Result, SituwaitionError<Self::Error>>;
}

/// 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<Self::Result, SituwaitionError<Self::Error>>;
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/async_std.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
#![cfg(feature = "async-std")]

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<F, A, R, E> AsyncSituwaition for AsyncWaiter<F, A, R, E>
impl<F, A, R, E> AsyncStdAsyncSituwaition for AsyncWaiter<F, A, R, E>
where
F: Future<Output = Result<R, E>> + Send,
A: Fn() -> F + Send,
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
#![cfg(feature = "tokio")]

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<F, A, R, E> AsyncSituwaition for AsyncWaiter<F, A, R, E>
impl<F, A, R, E> TokioAsyncSituwaition for AsyncWaiter<F, A, R, E>
where
F: Future<Output = Result<R, E>> + Send,
A: Fn() -> F + Send,
Expand Down