Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Enable feature gated docs labels
Browse files Browse the repository at this point in the history
We have an experimental feature of the rustdocs build that adds labels
for types/functions/modules ect. that are feature gated. Enable the
experimental feature and add compiler attributes to all non-test code
that is feature gated.
  • Loading branch information
tcharding committed Apr 26, 2022
1 parent ddd2b93 commit ae03655
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl fmt::Display for Error {

/// Trait for objects that can be serialized as hex strings.
#[cfg(any(test, feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(test, feature = "std", feature = "alloc"))))]
pub trait ToHex {
/// Converts to a hexadecimal representation of the object.
fn to_hex(&self) -> String;
Expand All @@ -70,6 +71,7 @@ pub trait FromHex: Sized {
}

#[cfg(any(test, feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(test, feature = "std", feature = "alloc"))))]
impl<T: fmt::LowerHex> ToHex for T {
/// Outputs the hash in hexadecimal form.
fn to_hex(&self) -> String {
Expand Down Expand Up @@ -142,6 +144,7 @@ impl<'a> Iterator for HexIterator<'a> {
}

#[cfg(any(feature = "std", feature = "core2"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "core2"))))]
impl<'a> io::Read for HexIterator<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut bytes_read = 0usize;
Expand Down Expand Up @@ -205,6 +208,7 @@ pub fn format_hex_reverse(data: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
}

#[cfg(any(test, feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(test, feature = "std", feature = "alloc"))))]
impl ToHex for [u8] {
fn to_hex(&self) -> String {
use core::fmt::Write;
Expand All @@ -217,6 +221,7 @@ impl ToHex for [u8] {
}

#[cfg(any(test, feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl FromHex for Vec<u8> {
fn from_byte_iter<I>(iter: I) -> Result<Self, Error>
where
Expand Down
2 changes: 2 additions & 0 deletions src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,15 @@ impl<T: HashTrait> HashTrait for Hmac<T> {
}

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<T: HashTrait + Serialize> Serialize for Hmac<T> {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
Serialize::serialize(&self.0, s)
}
}

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de, T: HashTrait + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Hmac<T>, D::Error> {
let inner = Deserialize::deserialize(d)?;
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#![deny(unused_mut)]
#![deny(missing_docs)]

// Experimental features we need
#![cfg_attr(docsrs, feature(doc_cfg))]

// In general, rust is absolutely horrid at supporting users doing things like,
// for example, compiling Rust code for real environments. Disable useless lints
// that don't do anything but annoy us and cant actually ever be resolved.
Expand Down
3 changes: 3 additions & 0 deletions src/serde_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/// Functions used by serde impls of all hashes.
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub mod serde_details {
use Error;

Expand Down Expand Up @@ -123,6 +124,7 @@ pub mod serde_details {
/// represents a newtype over a byte-slice over length `$len`.
#[macro_export]
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
macro_rules! serde_impl(
($t:ident, $len:expr) => (
impl $crate::serde_macros::serde_details::SerdeHash for $t {
Expand All @@ -148,6 +150,7 @@ macro_rules! serde_impl(
/// Does an "empty" serde implementation for the configuration without serde feature.
#[macro_export]
#[cfg(not(feature = "serde"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "serde"))))]
macro_rules! serde_impl(
($t:ident, $len:expr) => ()
);
1 change: 1 addition & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ macro_rules! hash_newtype {
}

#[cfg(feature = "schemars")]
#[cfg_attr(docsrs, doc(cfg(feature = "schemars")))]
pub mod json_hex_string {
use schemars::schema::{Schema, SchemaObject};
use schemars::{gen::SchemaGenerator, JsonSchema};
Expand Down

0 comments on commit ae03655

Please sign in to comment.