Skip to content

Commit 0740587

Browse files
committed
Use the unstable #[doc(cfg)] to document the tokio feature
rust-lang/rust#43781
1 parent 627b51a commit 0740587

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

.cirrus.yml

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ test_task:
2222
- cargo test
2323
- fi
2424
- cargo test --no-default-features
25+
doc_script:
26+
- if rustc --version | grep -q nightly; then
27+
- cargo doc --all-features --no-deps
28+
- fi
2529
before_cache_script: rm -rf $CARGO_HOME/registry/index
2630

2731
codecov_task:

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## 0.3.1 - 2018-12-26
1+
## [Unreleased] - ReleaseDate
2+
### Changed
3+
- Better documentation
4+
([#15](https://github.com/asomers/futures-locks/pull/15))
5+
6+
## [0.3.1] - 2018-12-26
27
### Changed
38
- Minimum compiler version has increased to 1.31.0
49
([#10](https://github.com/asomers/futures-locks/pull/10))

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ autotests = false
1919

2020
[features]
2121
default = ["tokio"]
22+
# For building documentation only; no functional change to the library.
23+
nightly-docs = []
24+
# Enable methods that require a Tokio executor.
2225
tokio = ["tokio-current-thread", "tokio-executor"]
2326

2427
[dependencies]

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//! [`Futures`]: https://github.com/rust-lang-nursery/futures-rs
88
//! [`Tokio`]: https:/tokio.rs
99
10+
#![cfg_attr(feature = "nightly-docs", feature(doc_cfg))]
11+
1012
extern crate futures;
1113
#[cfg(feature = "tokio")] extern crate tokio_current_thread;
1214
#[cfg(feature = "tokio")] extern crate tokio_executor;

src/mutex.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,6 @@ impl<T: 'static + ?Sized> Mutex<T> {
295295
/// separate task. Returns a `Future` containing the result of the
296296
/// computation.
297297
///
298-
/// *This method requires Futures-locks to be build with the `"tokio"`
299-
/// feature.*
300-
///
301298
/// When using Tokio, this method will often hold the `Mutex` for less time
302299
/// than chaining a computation to [`lock`](#method.lock). The reason is
303300
/// that Tokio polls all tasks promptly upon notification. However, Tokio
@@ -328,7 +325,8 @@ impl<T: 'static + ?Sized> Mutex<T> {
328325
/// assert_eq!(mtx.try_unwrap().unwrap(), 5);
329326
/// # }
330327
/// ```
331-
#[cfg(feature = "tokio")]
328+
#[cfg(any(feature = "tokio", all(feature = "nightly-docs", rustdoc)))]
329+
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "tokio")))]
332330
pub fn with<F, B, R, E>(&self, f: F)
333331
-> Result<impl Future<Item = R, Error = E>, SpawnError>
334332
where F: FnOnce(MutexGuard<T>) -> B + Send + 'static,
@@ -357,9 +355,6 @@ impl<T: 'static + ?Sized> Mutex<T> {
357355
/// Like [`with`](#method.with) but for Futures that aren't `Send`.
358356
/// Spawns a new task on a single-threaded Runtime to complete the Future.
359357
///
360-
/// *This method requires Futures-locks to be build with the `"tokio"`
361-
/// feature.*
362-
///
363358
/// # Examples
364359
///
365360
/// ```
@@ -384,7 +379,8 @@ impl<T: 'static + ?Sized> Mutex<T> {
384379
/// assert_eq!(*mtx.try_unwrap().unwrap(), 5);
385380
/// # }
386381
/// ```
387-
#[cfg(feature = "tokio")]
382+
#[cfg(any(feature = "tokio", all(feature = "nightly-docs", rustdoc)))]
383+
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "tokio")))]
388384
pub fn with_local<F, B, R, E>(&self, f: F)
389385
-> Result<impl Future<Item = R, Error = E>, SpawnError>
390386
where F: FnOnce(MutexGuard<T>) -> B + 'static,

src/rwlock.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,6 @@ impl<T: 'static + ?Sized> RwLock<T> {
489489
/// guarded value in a separate task. Returns a `Future` containing the
490490
/// result of the computation.
491491
///
492-
/// *This method requires Futures-locks to be build with the `"tokio"`
493-
/// feature.*
494-
///
495492
/// When using Tokio, this method will often hold the `RwLock` for less time
496493
/// than chaining a computation to [`read`](#method.read). The reason is
497494
/// that Tokio polls all tasks promptly upon notification. However, Tokio
@@ -520,7 +517,8 @@ impl<T: 'static + ?Sized> RwLock<T> {
520517
/// assert_eq!(r, Ok(5));
521518
/// # }
522519
/// ```
523-
#[cfg(feature = "tokio")]
520+
#[cfg(any(feature = "tokio", all(feature = "nightly-docs", rustdoc)))]
521+
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "tokio")))]
524522
pub fn with_read<F, B, R, E>(&self, f: F)
525523
-> Result<impl Future<Item = R, Error = E>, SpawnError>
526524
where F: FnOnce(RwLockReadGuard<T>) -> B + Send + 'static,
@@ -550,9 +548,6 @@ impl<T: 'static + ?Sized> RwLock<T> {
550548
/// `Send`. Spawns a new task on a single-threaded Runtime to complete the
551549
/// Future.
552550
///
553-
/// *This method requires Futures-locks to be build with the `"tokio"`
554-
/// feature.*
555-
///
556551
/// # Examples
557552
///
558553
/// ```
@@ -575,7 +570,8 @@ impl<T: 'static + ?Sized> RwLock<T> {
575570
/// assert_eq!(r, Ok(5));
576571
/// # }
577572
/// ```
578-
#[cfg(feature = "tokio")]
573+
#[cfg(any(feature = "tokio", all(feature = "nightly-docs", rustdoc)))]
574+
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "tokio")))]
579575
pub fn with_read_local<F, B, R, E>(&self, f: F)
580576
-> Result<impl Future<Item = R, Error = E>, SpawnError>
581577
where F: FnOnce(RwLockReadGuard<T>) -> B + 'static,
@@ -604,9 +600,6 @@ impl<T: 'static + ?Sized> RwLock<T> {
604600
/// guarded value in a separate task. Returns a `Future` containing the
605601
/// result of the computation.
606602
///
607-
/// *This method requires Futures-locks to be build with the `"tokio"`
608-
/// feature.*
609-
///
610603
/// When using Tokio, this method will often hold the `RwLock` for less time
611604
/// than chaining a computation to [`write`](#method.write). The reason is
612605
/// that Tokio polls all tasks promptly upon notification. However, Tokio
@@ -637,7 +630,8 @@ impl<T: 'static + ?Sized> RwLock<T> {
637630
/// assert_eq!(rwlock.try_unwrap().unwrap(), 5);
638631
/// # }
639632
/// ```
640-
#[cfg(feature = "tokio")]
633+
#[cfg(any(feature = "tokio", all(feature = "nightly-docs", rustdoc)))]
634+
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "tokio")))]
641635
pub fn with_write<F, B, R, E>(&self, f: F)
642636
-> Result<impl Future<Item = R, Error = E>, SpawnError>
643637
where F: FnOnce(RwLockWriteGuard<T>) -> B + Send + 'static,
@@ -667,9 +661,6 @@ impl<T: 'static + ?Sized> RwLock<T> {
667661
/// `Send`. Spawns a new task on a single-threaded Runtime to complete the
668662
/// Future.
669663
///
670-
/// *This method requires Futures-locks to be build with the `"tokio"`
671-
/// feature.*
672-
///
673664
/// # Examples
674665
///
675666
/// ```
@@ -694,7 +685,8 @@ impl<T: 'static + ?Sized> RwLock<T> {
694685
/// assert_eq!(*rwlock.try_unwrap().unwrap(), 5);
695686
/// # }
696687
/// ```
697-
#[cfg(feature = "tokio")]
688+
#[cfg(any(feature = "tokio", all(feature = "nightly-docs", rustdoc)))]
689+
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "tokio")))]
698690
pub fn with_write_local<F, B, R, E>(&self, f: F)
699691
-> Result<impl Future<Item = R, Error = E>, SpawnError>
700692
where F: FnOnce(RwLockWriteGuard<T>) -> B + 'static,

0 commit comments

Comments
 (0)