From 9ae81ac978a0e8fc6181fd61fe584c2f14fbdba6 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Sun, 25 Oct 2020 17:55:04 +0200 Subject: [PATCH 1/4] add doc(cfg) attributes --- Cargo.toml | 1 + src/bot/download.rs | 1 + src/dispatching/dialogue/mod.rs | 1 + src/dispatching/dialogue/storage/mod.rs | 1 + src/dispatching/dialogue/storage/serializer.rs | 4 ++++ src/lib.rs | 9 ++++++--- src/net/download.rs | 1 + src/net/mod.rs | 1 + src/prelude.rs | 1 + src/utils/mod.rs | 1 + 10 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ff51eb5..6839457b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,7 @@ tokio = { version = "0.2.21", features = ["fs", "stream", "rt-threaded", "macros [package.metadata."docs.rs"] all-features = true +rustdoc-args = ["--cfg", "docsrs"] [[test]] name = "redis" diff --git a/src/bot/download.rs b/src/bot/download.rs index 7035cfe7..91e5b692 100644 --- a/src/bot/download.rs +++ b/src/bot/download.rs @@ -56,6 +56,7 @@ impl Bot { /// [`tokio::fs::File`]: tokio::fs::File /// [`Bot::download_file`]: crate::Bot::download_file #[cfg(feature = "unstable-stream")] + #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] pub async fn download_file_stream( &self, path: &str, diff --git a/src/dispatching/dialogue/mod.rs b/src/dispatching/dialogue/mod.rs index 00bdc6cf..255b3678 100644 --- a/src/dispatching/dialogue/mod.rs +++ b/src/dispatching/dialogue/mod.rs @@ -162,6 +162,7 @@ pub use transition::{ pub use teloxide_macros::Transition; #[cfg(feature = "redis-storage")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))] pub use storage::{RedisStorage, RedisStorageError}; pub use storage::{serializer, InMemStorage, Serializer, Storage}; diff --git a/src/dispatching/dialogue/storage/mod.rs b/src/dispatching/dialogue/storage/mod.rs index ed5319c8..2c2d943d 100644 --- a/src/dispatching/dialogue/storage/mod.rs +++ b/src/dispatching/dialogue/storage/mod.rs @@ -9,6 +9,7 @@ use futures::future::BoxFuture; pub use in_mem_storage::InMemStorage; #[cfg(feature = "redis-storage")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))] pub use redis_storage::{RedisStorage, RedisStorageError}; pub use serializer::Serializer; use std::sync::Arc; diff --git a/src/dispatching/dialogue/storage/serializer.rs b/src/dispatching/dialogue/storage/serializer.rs index 20fa4841..7154c01b 100644 --- a/src/dispatching/dialogue/storage/serializer.rs +++ b/src/dispatching/dialogue/storage/serializer.rs @@ -32,9 +32,11 @@ where /// /// [CBOR]: https://en.wikipedia.org/wiki/CBOR #[cfg(feature = "cbor-serializer")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))] pub struct CBOR; #[cfg(feature = "cbor-serializer")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))] impl Serializer for CBOR where D: Serialize + DeserializeOwned, @@ -54,9 +56,11 @@ where /// /// [Bincode]: https://github.com/servo/bincode #[cfg(feature = "bincode-serializer")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "bincode-serializer")))] pub struct Bincode; #[cfg(feature = "bincode-serializer")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "bincode-serializer")))] impl Serializer for Bincode where D: Serialize + DeserializeOwned, diff --git a/src/lib.rs b/src/lib.rs index 08ffe910..3e788bfb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,6 +41,12 @@ #![allow(clippy::match_bool)] #![forbid(unsafe_code)] #![cfg_attr(all(feature = "nightly", doctest), feature(external_doc))] +// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.` +// +// To properly build docs of this crate run +// ```console +// $ RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --open --all-features +// ``` #![cfg_attr(all(docsrs, feature = "nightly"), feature(doc_cfg))] pub use bot::{Bot, BotBuilder}; @@ -62,9 +68,6 @@ pub mod requests; pub mod types; pub mod utils; -#[cfg(feature = "macros")] -extern crate teloxide_macros; - #[cfg(feature = "macros")] #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] pub use teloxide_macros::teloxide; diff --git a/src/net/download.rs b/src/net/download.rs index 05f08f5d..091e799c 100644 --- a/src/net/download.rs +++ b/src/net/download.rs @@ -28,6 +28,7 @@ where } #[cfg(feature = "unstable-stream")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] pub async fn download_file_stream( client: &Client, token: &str, diff --git a/src/net/mod.rs b/src/net/mod.rs index b4944959..ad02bcf1 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -1,4 +1,5 @@ #[cfg(feature = "unstable-stream")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] pub use download::download_file_stream; pub use self::{ diff --git a/src/prelude.rs b/src/prelude.rs index a7ce757e..92dab5b7 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -15,6 +15,7 @@ pub use crate::{ }; #[cfg(feature = "frunk")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "frunk")))] pub use crate::utils::UpState; pub use tokio::sync::mpsc::UnboundedReceiver; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 6882383b..9bdedba9 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -9,4 +9,5 @@ mod up_state; pub use client_from_env::client_from_env; #[cfg(feature = "frunk")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "frunk")))] pub use up_state::UpState; From 43cdedb06a7ddbbf30208eb60fecdc7b12ddcdea Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Sun, 25 Oct 2020 18:19:44 +0200 Subject: [PATCH 2/4] Readme "nightly" feature comment update --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6839457b..e41a7df7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ frunk- = ["frunk"] macros = ["teloxide-macros"] -nightly = [] # currently used only for `README.md` tests +nightly = [] # currently used for `README.md` tests and building docs for `docsrs` to add `This is supported on feature="..." only.` [dependencies] serde_json = "1.0.55" From 656db8273bc498e29a10109b70b867824394d8f1 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev <8925621+elpiel@users.noreply.github.com> Date: Mon, 26 Oct 2020 07:27:13 +0200 Subject: [PATCH 3/4] Update Cargo.toml docs.rs metadata Co-authored-by: Waffle Lapkin --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e41a7df7..fb572048 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,7 @@ pretty_env_logger = "0.4.0" lazy_static = "1.4.0" tokio = { version = "0.2.21", features = ["fs", "stream", "rt-threaded", "macros"] } -[package.metadata."docs.rs"] +[package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] From 508f34148beb567e71b691dbe3ef205105834454 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 26 Oct 2020 12:12:06 +0200 Subject: [PATCH 4/4] replace occurences of `docsrs` and add FIXME --- src/bot/download.rs | 3 ++- src/dispatching/dialogue/mod.rs | 6 ++++-- src/dispatching/dialogue/storage/mod.rs | 3 ++- src/dispatching/dialogue/storage/serializer.rs | 12 ++++++++---- src/lib.rs | 9 ++++++--- src/net/download.rs | 3 ++- src/net/mod.rs | 3 ++- src/prelude.rs | 3 ++- src/utils/command.rs | 3 ++- src/utils/mod.rs | 3 ++- 10 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/bot/download.rs b/src/bot/download.rs index 91e5b692..0dec6543 100644 --- a/src/bot/download.rs +++ b/src/bot/download.rs @@ -56,7 +56,8 @@ impl Bot { /// [`tokio::fs::File`]: tokio::fs::File /// [`Bot::download_file`]: crate::Bot::download_file #[cfg(feature = "unstable-stream")] - #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] + // FIXME(waffle): use `docsrs` here when issue with combine is resolved + #[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] pub async fn download_file_stream( &self, path: &str, diff --git a/src/dispatching/dialogue/mod.rs b/src/dispatching/dialogue/mod.rs index 255b3678..883e6c8f 100644 --- a/src/dispatching/dialogue/mod.rs +++ b/src/dispatching/dialogue/mod.rs @@ -158,11 +158,13 @@ pub use transition::{ }; #[cfg(feature = "macros")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] pub use teloxide_macros::Transition; #[cfg(feature = "redis-storage")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))] pub use storage::{RedisStorage, RedisStorageError}; pub use storage::{serializer, InMemStorage, Serializer, Storage}; diff --git a/src/dispatching/dialogue/storage/mod.rs b/src/dispatching/dialogue/storage/mod.rs index 2c2d943d..ab8181cf 100644 --- a/src/dispatching/dialogue/storage/mod.rs +++ b/src/dispatching/dialogue/storage/mod.rs @@ -9,7 +9,8 @@ use futures::future::BoxFuture; pub use in_mem_storage::InMemStorage; #[cfg(feature = "redis-storage")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))] pub use redis_storage::{RedisStorage, RedisStorageError}; pub use serializer::Serializer; use std::sync::Arc; diff --git a/src/dispatching/dialogue/storage/serializer.rs b/src/dispatching/dialogue/storage/serializer.rs index 7154c01b..16ce266a 100644 --- a/src/dispatching/dialogue/storage/serializer.rs +++ b/src/dispatching/dialogue/storage/serializer.rs @@ -32,11 +32,13 @@ where /// /// [CBOR]: https://en.wikipedia.org/wiki/CBOR #[cfg(feature = "cbor-serializer")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))] pub struct CBOR; #[cfg(feature = "cbor-serializer")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))] impl Serializer for CBOR where D: Serialize + DeserializeOwned, @@ -56,11 +58,13 @@ where /// /// [Bincode]: https://github.com/servo/bincode #[cfg(feature = "bincode-serializer")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "bincode-serializer")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "bincode-serializer")))] pub struct Bincode; #[cfg(feature = "bincode-serializer")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "bincode-serializer")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "bincode-serializer")))] impl Serializer for Bincode where D: Serialize + DeserializeOwned, diff --git a/src/lib.rs b/src/lib.rs index 3e788bfb..8639abd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,9 +45,11 @@ // // To properly build docs of this crate run // ```console -// $ RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --open --all-features +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +// $ RUSTDOCFLAGS="--cfg teloxide_docsrs" cargo +nightly doc --open --all-features // ``` -#![cfg_attr(all(docsrs, feature = "nightly"), feature(doc_cfg))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#![cfg_attr(all(teloxide_docsrs, feature = "nightly"), feature(doc_cfg))] pub use bot::{Bot, BotBuilder}; pub use dispatching::repls::{ @@ -69,7 +71,8 @@ pub mod types; pub mod utils; #[cfg(feature = "macros")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] pub use teloxide_macros::teloxide; #[cfg(all(feature = "nightly", doctest))] diff --git a/src/net/download.rs b/src/net/download.rs index 091e799c..6f9c87b0 100644 --- a/src/net/download.rs +++ b/src/net/download.rs @@ -28,7 +28,8 @@ where } #[cfg(feature = "unstable-stream")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] pub async fn download_file_stream( client: &Client, token: &str, diff --git a/src/net/mod.rs b/src/net/mod.rs index ad02bcf1..118b6036 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -1,5 +1,6 @@ #[cfg(feature = "unstable-stream")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "unstable-stream")))] pub use download::download_file_stream; pub use self::{ diff --git a/src/prelude.rs b/src/prelude.rs index 92dab5b7..61773b4e 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -15,7 +15,8 @@ pub use crate::{ }; #[cfg(feature = "frunk")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "frunk")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "frunk")))] pub use crate::utils::UpState; pub use tokio::sync::mpsc::UnboundedReceiver; diff --git a/src/utils/command.rs b/src/utils/command.rs index a2bd4c22..5e9c034d 100644 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -50,7 +50,8 @@ use serde::export::Formatter; use std::{error::Error, fmt::Display}; #[cfg(feature = "macros")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] pub use teloxide_macros::BotCommand; /// An enumeration of bot's commands. diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 9bdedba9..e20a7a81 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -9,5 +9,6 @@ mod up_state; pub use client_from_env::client_from_env; #[cfg(feature = "frunk")] -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "frunk")))] +// FIXME(waffle): use `docsrs` here when issue with combine is resolved +#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "frunk")))] pub use up_state::UpState;