From bdc120b06a1ee03ae5e2b4bdcdc1b9f1ea75409c Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Mon, 13 May 2024 16:17:37 +0200 Subject: [PATCH] Use well-known docsrs cfg for docs.rs (#146) See https://github.com/rust-lang/cargo/pull/13383 for the PR adding support. --- Cargo.toml | 2 +- src/de/flavors.rs | 2 +- src/de/mod.rs | 4 ++-- src/lib.rs | 6 +++--- src/max_size.rs | 10 +++++----- src/schema.rs | 8 ++++---- src/ser/flavors.rs | 6 +++--- src/ser/mod.rs | 20 ++++++++++---------- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f7c4f99..7990a70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ documentation = "https://docs.rs/postcard/" [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "doc_cfg"] +rustdoc-args = ["--cfg", "docsrs"] [dependencies] diff --git a/src/de/flavors.rs b/src/de/flavors.rs index e5a3d19..2b15138 100644 --- a/src/de/flavors.rs +++ b/src/de/flavors.rs @@ -387,7 +387,7 @@ pub mod io { /// /// More on CRCs: . #[cfg(feature = "use-crc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-crc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-crc")))] pub mod crc { use core::convert::TryInto; diff --git a/src/de/mod.rs b/src/de/mod.rs index 4910150..b7c3424 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -98,7 +98,7 @@ where /// /// See the `de_flavors::crc` module for the complete set of functions. #[cfg(feature = "use-crc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-crc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-crc")))] #[inline] pub fn from_bytes_crc32<'a, T>(s: &'a [u8], digest: crc::Digest<'a, u32>) -> Result where @@ -112,7 +112,7 @@ where /// /// See the `de_flavors::crc` module for the complete set of functions. #[cfg(feature = "use-crc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-crc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-crc")))] #[inline] pub fn take_from_bytes_crc32<'a, T>( s: &'a [u8], diff --git a/src/lib.rs b/src/lib.rs index 48e42fb..92afc1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(any(test, feature = "use-std")), no_std)] #![warn(missing_docs)] #![cfg_attr(not(doctest), doc = include_str!("../README.md"))] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] pub mod accumulator; mod de; @@ -66,7 +66,7 @@ pub mod schema; pub mod experimental { /// Compile time max-serialization size calculation #[cfg(feature = "experimental-derive")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "experimental-derive")))] + #[cfg_attr(docsrs, doc(cfg(feature = "experimental-derive")))] pub mod max_size { // NOTE: This is the trait... pub use crate::max_size::MaxSize; @@ -78,7 +78,7 @@ pub mod experimental { /// Compile time Schema generation #[cfg(feature = "experimental-derive")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "experimental-derive")))] + #[cfg_attr(docsrs, doc(cfg(feature = "experimental-derive")))] pub mod schema { // NOTE: This is the trait... pub use crate::schema::{NamedType, NamedValue, NamedVariant, Schema, SdmTy, Varint}; diff --git a/src/max_size.rs b/src/max_size.rs index 4dea531..69ceebd 100644 --- a/src/max_size.rs +++ b/src/max_size.rs @@ -199,31 +199,31 @@ impl Max } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] impl MaxSize for Box { const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE; } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] impl MaxSize for Arc { const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE; } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] impl MaxSize for Rc { const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE; } #[cfg(feature = "heapless")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] impl MaxSize for heapless::Vec { const POSTCARD_MAX_SIZE: usize = <[T; N]>::POSTCARD_MAX_SIZE + varint_size(N); } #[cfg(feature = "heapless")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] impl MaxSize for heapless::String { const POSTCARD_MAX_SIZE: usize = <[u8; N]>::POSTCARD_MAX_SIZE + varint_size(N); } diff --git a/src/schema.rs b/src/schema.rs index c55aa3d..4a17cc1 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -226,7 +226,7 @@ impl Schema for [T; N] { } #[cfg(feature = "heapless")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] impl Schema for heapless::Vec { const SCHEMA: &'static NamedType = &NamedType { name: "heapless::Vec", @@ -234,7 +234,7 @@ impl Schema for heapless::Vec { }; } #[cfg(feature = "heapless")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] impl Schema for heapless::String { const SCHEMA: &'static NamedType = &NamedType { name: "heapless::String", @@ -243,7 +243,7 @@ impl Schema for heapless::String { } #[cfg(feature = "use-std")] -#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "use-std"))))] +#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))] impl Schema for std::vec::Vec { const SCHEMA: &'static NamedType = &NamedType { name: "Vec", @@ -252,7 +252,7 @@ impl Schema for std::vec::Vec { } #[cfg(feature = "use-std")] -#[cfg_attr(doc_cfg, doc(cfg(any(feature = "alloc", feature = "use-std"))))] +#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "use-std"))))] impl Schema for std::string::String { const SCHEMA: &'static NamedType = &NamedType { name: "String", diff --git a/src/ser/flavors.rs b/src/ser/flavors.rs index 7519ccb..bad668b 100644 --- a/src/ser/flavors.rs +++ b/src/ser/flavors.rs @@ -572,7 +572,7 @@ where /// /// More on CRCs: . #[cfg(feature = "use-crc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-crc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-crc")))] pub mod crc { use crc::Digest; use crc::Width; @@ -652,7 +652,7 @@ pub mod crc { /// Serialize a `T` to a `heapless::Vec`, with the `Vec` containing /// data followed by a CRC. The CRC bytes are included in the output `Vec`. #[cfg(feature = "heapless")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] + #[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] pub fn []( value: &T, digest: Digest<'_, $int>, @@ -668,7 +668,7 @@ pub mod crc { /// Serialize a `T` to a `heapless::Vec`, with the `Vec` containing /// data followed by a CRC. The CRC bytes are included in the output `Vec`. #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] + #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub fn [](value: &T, digest: Digest<'_, $int>) -> Result> where T: Serialize + ?Sized, diff --git a/src/ser/mod.rs b/src/ser/mod.rs index eddf826..e75ba78 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -116,7 +116,7 @@ where /// assert_eq!(ser.deref(), &[0x02, 0x01, 0x03, 0x20, 0x30, 0x00]); /// ``` #[cfg(feature = "heapless")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] pub fn to_vec_cobs(value: &T) -> Result> where T: Serialize + ?Sized, @@ -150,7 +150,7 @@ where /// assert_eq!(ser.deref(), &[0x01, 0x00, 0x20, 0x30]); /// ``` #[cfg(feature = "heapless")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] pub fn to_vec(value: &T) -> Result> where T: Serialize + ?Sized, @@ -172,7 +172,7 @@ where /// assert_eq!(ser.as_slice(), &[0x03, b'H', b'i', b'!']); /// ``` #[cfg(feature = "use-std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-std")))] #[inline] pub fn to_stdvec(value: &T) -> Result> where @@ -197,7 +197,7 @@ where /// assert_eq!(ser.as_slice(), &[0x05, 0x03, b'H', b'i', b'!', 0x00]); /// ``` #[cfg(feature = "use-std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-std")))] #[inline] pub fn to_stdvec_cobs(value: &T) -> Result> where @@ -220,7 +220,7 @@ where /// assert_eq!(ser.as_slice(), &[0x03, b'H', b'i', b'!']); /// ``` #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub fn to_allocvec(value: &T) -> Result> where T: Serialize + ?Sized, @@ -244,7 +244,7 @@ where /// assert_eq!(ser.as_slice(), &[0x05, 0x03, b'H', b'i', b'!', 0x00]); /// ``` #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub fn to_allocvec_cobs(value: &T) -> Result> where T: Serialize + ?Sized, @@ -337,7 +337,7 @@ where /// /// See the `ser_flavors::crc` module for the complete set of functions. #[cfg(feature = "use-crc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "use-crc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "use-crc")))] #[inline] pub fn to_slice_crc32<'a, T>( value: &T, @@ -373,7 +373,7 @@ where /// /// See the `ser_flavors::crc` module for the complete set of functions. #[cfg(all(feature = "use-crc", feature = "heapless"))] -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "use-crc", feature = "heapless"))))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "use-crc", feature = "heapless"))))] #[inline] pub fn to_vec_crc32( value: &T, @@ -407,7 +407,7 @@ where /// /// See the `ser_flavors::crc` module for the complete set of functions. #[cfg(all(feature = "use-crc", feature = "use-std"))] -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "use-crc", feature = "use-std"))))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "use-crc", feature = "use-std"))))] #[inline] pub fn to_stdvec_crc32(value: &T, digest: crc::Digest<'_, u32>) -> Result> where @@ -438,7 +438,7 @@ where /// /// See the `ser_flavors::crc` module for the complete set of functions. #[cfg(all(feature = "use-crc", feature = "alloc"))] -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "use-crc", feature = "alloc"))))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "use-crc", feature = "alloc"))))] #[inline] pub fn to_allocvec_crc32( value: &T,