Skip to content

Commit

Permalink
Use well-known docsrs cfg for docs.rs (#146)
Browse files Browse the repository at this point in the history
See rust-lang/cargo#13383 for the PR adding support.
  • Loading branch information
ia0 authored May 13, 2024
1 parent a2525a6 commit bdc120b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion src/de/flavors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub mod io {
///
/// More on CRCs: <https://en.wikipedia.org/wiki/Cyclic_redundancy_check>.
#[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;

Expand Down
4 changes: 2 additions & 2 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
where
Expand All @@ -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],
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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};
Expand Down
10 changes: 5 additions & 5 deletions src/max_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,31 +199,31 @@ impl<A: MaxSize, B: MaxSize, C: MaxSize, D: MaxSize, E: MaxSize, F: MaxSize> Max
}

#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: MaxSize> MaxSize for Box<T> {
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<T: MaxSize> MaxSize for Arc<T> {
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<T: MaxSize> MaxSize for Rc<T> {
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<T: MaxSize, const N: usize> MaxSize for heapless::Vec<T, N> {
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<const N: usize> MaxSize for heapless::String<N> {
const POSTCARD_MAX_SIZE: usize = <[u8; N]>::POSTCARD_MAX_SIZE + varint_size(N);
}
Expand Down
8 changes: 4 additions & 4 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ impl<T: Schema, const N: usize> Schema for [T; N] {
}

#[cfg(feature = "heapless")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))]
#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))]
impl<T: Schema, const N: usize> Schema for heapless::Vec<T, N> {
const SCHEMA: &'static NamedType = &NamedType {
name: "heapless::Vec<T, N>",
ty: &SdmTy::Seq(T::SCHEMA),
};
}
#[cfg(feature = "heapless")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))]
#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))]
impl<const N: usize> Schema for heapless::String<N> {
const SCHEMA: &'static NamedType = &NamedType {
name: "heapless::String<N>",
Expand All @@ -243,7 +243,7 @@ impl<const N: usize> Schema for heapless::String<N> {
}

#[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<T: Schema> Schema for std::vec::Vec<T> {
const SCHEMA: &'static NamedType = &NamedType {
name: "Vec<T>",
Expand All @@ -252,7 +252,7 @@ impl<T: Schema> Schema for std::vec::Vec<T> {
}

#[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",
Expand Down
6 changes: 3 additions & 3 deletions src/ser/flavors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ where
///
/// More on CRCs: <https://en.wikipedia.org/wiki/Cyclic_redundancy_check>.
#[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;
Expand Down Expand Up @@ -652,7 +652,7 @@ pub mod crc {
/// Serialize a `T` to a `heapless::Vec<u8>`, 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 [<to_vec_ $int>]<T, const B: usize>(
value: &T,
digest: Digest<'_, $int>,
Expand All @@ -668,7 +668,7 @@ pub mod crc {
/// Serialize a `T` to a `heapless::Vec<u8>`, 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 [<to_allocvec_ $int>]<T>(value: &T, digest: Digest<'_, $int>) -> Result<alloc::vec::Vec<u8>>
where
T: Serialize + ?Sized,
Expand Down
20 changes: 10 additions & 10 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, const B: usize>(value: &T) -> Result<Vec<u8, B>>
where
T: Serialize + ?Sized,
Expand Down Expand Up @@ -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<T, const B: usize>(value: &T) -> Result<Vec<u8, B>>
where
T: Serialize + ?Sized,
Expand All @@ -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<T>(value: &T) -> Result<std::vec::Vec<u8>>
where
Expand All @@ -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<T>(value: &T) -> Result<std::vec::Vec<u8>>
where
Expand All @@ -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<T>(value: &T) -> Result<alloc::vec::Vec<u8>>
where
T: Serialize + ?Sized,
Expand All @@ -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<T>(value: &T) -> Result<alloc::vec::Vec<u8>>
where
T: Serialize + ?Sized,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<T, const B: usize>(
value: &T,
Expand Down Expand Up @@ -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<T>(value: &T, digest: crc::Digest<'_, u32>) -> Result<std::vec::Vec<u8>>
where
Expand Down Expand Up @@ -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<T>(
value: &T,
Expand Down

0 comments on commit bdc120b

Please sign in to comment.