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

Commit 28aaca5

Browse files
committed
Merge #151: Use nightly docs features
ae03655 Enable feature gated docs labels (Tobin C. Harding) ddd2b93 Put cfg attributes under rustdocs (Tobin C. Harding) 3f32a31 Re-order features in compiler attribute (Tobin C. Harding) Pull request description: After #150 merges we can use the nightly toolchain and get access to the docrs compiler attribute. Patch 1 and 2 are cleanup in preparation for patch 3 which adds the experimental docrs cfg attribute of form ``` #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] ``` to all non-test code that is feature gated. ACKs for top commit: apoelstra: ACK ae03655 Tree-SHA512: 0e65f1dc827d7b6630511965c3dca2f7e978841210bdbe7d7e1e78dd42ac57be82701c4e95ecb0d16e6903870d5a28a154cd0e03d0f9fce5ffbfe52b6eb549d9
2 parents 05686c8 + ae03655 commit 28aaca5

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/hex.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl fmt::Display for Error {
5151

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

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

144146
#[cfg(any(feature = "std", feature = "core2"))]
147+
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "core2"))))]
145148
impl<'a> io::Read for HexIterator<'a> {
146149
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
147150
let mut bytes_read = 0usize;
@@ -204,7 +207,8 @@ pub fn format_hex_reverse(data: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
204207
Ok(())
205208
}
206209

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

219223
#[cfg(any(test, feature = "std", feature = "alloc"))]
224+
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
220225
impl FromHex for Vec<u8> {
221226
fn from_byte_iter<I>(iter: I) -> Result<Self, Error>
222227
where

src/hmac.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,15 @@ impl<T: HashTrait> HashTrait for Hmac<T> {
223223
}
224224

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

232233
#[cfg(feature = "serde")]
234+
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
233235
impl<'de, T: HashTrait + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
234236
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Hmac<T>, D::Error> {
235237
let inner = Deserialize::deserialize(d)?;

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#![deny(unused_mut)]
2828
#![deny(missing_docs)]
2929

30+
// Experimental features we need
31+
#![cfg_attr(docsrs, feature(doc_cfg))]
32+
3033
// In general, rust is absolutely horrid at supporting users doing things like,
3134
// for example, compiling Rust code for real environments. Disable useless lints
3235
// that don't do anything but annoy us and cant actually ever be resolved.

src/serde_macros.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
//! Macros for serde trait implementations, and supporting code.
1616
//!
1717
18-
#[cfg(feature = "serde")]
1918
/// Functions used by serde impls of all hashes.
19+
#[cfg(feature = "serde")]
20+
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
2021
pub mod serde_details {
2122
use Error;
2223

@@ -119,10 +120,11 @@ pub mod serde_details {
119120
}
120121
}
121122

122-
#[macro_export]
123-
#[cfg(feature = "serde")]
124123
/// Implements `Serialize` and `Deserialize` for a type `$t` which
125124
/// represents a newtype over a byte-slice over length `$len`.
125+
#[macro_export]
126+
#[cfg(feature = "serde")]
127+
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
126128
macro_rules! serde_impl(
127129
($t:ident, $len:expr) => (
128130
impl $crate::serde_macros::serde_details::SerdeHash for $t {
@@ -148,6 +150,7 @@ macro_rules! serde_impl(
148150
/// Does an "empty" serde implementation for the configuration without serde feature.
149151
#[macro_export]
150152
#[cfg(not(feature = "serde"))]
153+
#[cfg_attr(docsrs, doc(cfg(not(feature = "serde"))))]
151154
macro_rules! serde_impl(
152155
($t:ident, $len:expr) => ()
153156
);

src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ macro_rules! hash_newtype {
264264
}
265265

266266
#[cfg(feature = "schemars")]
267+
#[cfg_attr(docsrs, doc(cfg(feature = "schemars")))]
267268
pub mod json_hex_string {
268269
use schemars::schema::{Schema, SchemaObject};
269270
use schemars::{gen::SchemaGenerator, JsonSchema};

0 commit comments

Comments
 (0)