From 13be111de171cc27b7feaa64966dc3dd01f13daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sat, 20 Apr 2024 09:13:03 +0200 Subject: [PATCH] sasl: make docs.rs emit nice feature tags on feature-gated items --- sasl/Cargo.toml | 4 ++++ sasl/src/client/mechanisms/mod.rs | 1 + sasl/src/client/mod.rs | 2 ++ sasl/src/common/mod.rs | 1 + sasl/src/error.rs | 2 ++ sasl/src/lib.rs | 1 + sasl/src/secret.rs | 2 ++ sasl/src/server/mechanisms/mod.rs | 2 ++ sasl/src/server/mod.rs | 6 ++++++ 9 files changed, 21 insertions(+) diff --git a/sasl/Cargo.toml b/sasl/Cargo.toml index 994677b..9847144 100644 --- a/sasl/Cargo.toml +++ b/sasl/Cargo.toml @@ -26,3 +26,7 @@ sha-1 = { version = "0.10", optional = true } sha2 = { version = "0.10", optional = true } hmac = { version = "0.12", optional = true } pbkdf2 = { version = "0.12", default-features = false, optional = true } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/sasl/src/client/mechanisms/mod.rs b/sasl/src/client/mechanisms/mod.rs index bde2fcb..342dbc4 100644 --- a/sasl/src/client/mechanisms/mod.rs +++ b/sasl/src/client/mechanisms/mod.rs @@ -10,4 +10,5 @@ pub use self::anonymous::Anonymous; pub use self::plain::Plain; #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] pub use self::scram::Scram; diff --git a/sasl/src/client/mod.rs b/sasl/src/client/mod.rs index 8acca9f..3e8d0cf 100644 --- a/sasl/src/client/mod.rs +++ b/sasl/src/client/mod.rs @@ -34,6 +34,7 @@ pub enum MechanismError { } #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] impl From for MechanismError { fn from(err: DeriveError) -> MechanismError { MechanismError::DeriveError(err) @@ -41,6 +42,7 @@ impl From for MechanismError { } #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] impl From for MechanismError { fn from(err: InvalidLength) -> MechanismError { MechanismError::InvalidKeyLength(err) diff --git a/sasl/src/common/mod.rs b/sasl/src/common/mod.rs index 36d7e1d..a43cf2e 100644 --- a/sasl/src/common/mod.rs +++ b/sasl/src/common/mod.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::string::FromUtf8Error; #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] pub mod scram; #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/sasl/src/error.rs b/sasl/src/error.rs index eb88590..e5a11c5 100644 --- a/sasl/src/error.rs +++ b/sasl/src/error.rs @@ -5,6 +5,7 @@ use getrandom::Error as RngError; #[derive(Debug)] pub enum Error { #[cfg(feature = "scram")] + #[cfg_attr(docsrs, doc(cfg(feature = "scram")))] /// An error while initializing the Rng. RngError(RngError), /// An error in a SASL mechanism. @@ -12,6 +13,7 @@ pub enum Error { } #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] impl From for Error { fn from(err: RngError) -> Error { Error::RngError(err) diff --git a/sasl/src/lib.rs b/sasl/src/lib.rs index f85571a..9d3f006 100644 --- a/sasl/src/lib.rs +++ b/sasl/src/lib.rs @@ -1,4 +1,5 @@ //#![deny(missing_docs)] +#![cfg_attr(docsrs, feature(doc_cfg))] //! This crate provides a framework for SASL authentication and a few authentication mechanisms. //! diff --git a/sasl/src/secret.rs b/sasl/src/secret.rs index bfd5b4e..0ce57a7 100644 --- a/sasl/src/secret.rs +++ b/sasl/src/secret.rs @@ -23,6 +23,7 @@ pub struct Pbkdf2Sha1 { impl Pbkdf2Sha1 { #[cfg(feature = "scram")] + #[cfg_attr(docsrs, doc(cfg(feature = "scram")))] pub fn derive(password: &str, salt: &[u8], iterations: u32) -> Result { use crate::common::scram::{ScramProvider, Sha1}; use crate::common::Password; @@ -58,6 +59,7 @@ pub struct Pbkdf2Sha256 { impl Pbkdf2Sha256 { #[cfg(feature = "scram")] + #[cfg_attr(docsrs, doc(cfg(feature = "scram")))] pub fn derive( password: &str, salt: &[u8], diff --git a/sasl/src/server/mechanisms/mod.rs b/sasl/src/server/mechanisms/mod.rs index 1989a58..e7f907b 100644 --- a/sasl/src/server/mechanisms/mod.rs +++ b/sasl/src/server/mechanisms/mod.rs @@ -5,7 +5,9 @@ mod plain; mod scram; #[cfg(feature = "anonymous")] +#[cfg_attr(docsrs, doc(cfg(feature = "anonymous")))] pub use self::anonymous::Anonymous; pub use self::plain::Plain; #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] pub use self::scram::Scram; diff --git a/sasl/src/server/mod.rs b/sasl/src/server/mod.rs index 889abac..11555ac 100644 --- a/sasl/src/server/mod.rs +++ b/sasl/src/server/mod.rs @@ -36,6 +36,7 @@ pub trait Validator { pub enum ProviderError { AuthenticationFailed, #[cfg(feature = "scram")] + #[cfg_attr(docsrs, doc(cfg(feature = "scram")))] DeriveError(DeriveError), } @@ -65,8 +66,10 @@ pub enum MechanismError { CannotDecodeResponse, #[cfg(feature = "scram")] + #[cfg_attr(docsrs, doc(cfg(feature = "scram")))] InvalidKeyLength(hmac::digest::InvalidLength), #[cfg(any(feature = "scram", feature = "anonymous"))] + #[cfg_attr(docsrs, doc(cfg(any(feature = "scram", feature = "anonymous"))))] RandomFailure(getrandom::Error), NoProof, CannotDecodeProof, @@ -75,6 +78,7 @@ pub enum MechanismError { } #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] impl From for ProviderError { fn from(err: DeriveError) -> ProviderError { ProviderError::DeriveError(err) @@ -100,6 +104,7 @@ impl From for MechanismError { } #[cfg(feature = "scram")] +#[cfg_attr(docsrs, doc(cfg(feature = "scram")))] impl From for MechanismError { fn from(err: hmac::digest::InvalidLength) -> MechanismError { MechanismError::InvalidKeyLength(err) @@ -107,6 +112,7 @@ impl From for MechanismError { } #[cfg(any(feature = "scram", feature = "anonymous"))] +#[cfg_attr(docsrs, doc(cfg(any(feature = "scram", feature = "anonymous"))))] impl From for MechanismError { fn from(err: getrandom::Error) -> MechanismError { MechanismError::RandomFailure(err)