diff --git a/Cargo.toml b/Cargo.toml index b195863..882ea80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,3 +38,8 @@ serde = { version = "1.0.130", optional = true } serde_derive = "1.0.130" serde_json = "1.0.68" tempfile = "3.2.0" + + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/src/features/derive.rs b/src/features/derive.rs index b55c1b5..a7cb5d1 100644 --- a/src/features/derive.rs +++ b/src/features/derive.rs @@ -1 +1,2 @@ +#[cfg_attr(docsrs, doc(cfg(feature = "derive")))] pub use bincode_derive::{Decodable, Encodable}; diff --git a/src/features/impl_alloc.rs b/src/features/impl_alloc.rs index 4132a2f..6d00bfb 100644 --- a/src/features/impl_alloc.rs +++ b/src/features/impl_alloc.rs @@ -20,11 +20,13 @@ impl enc::write::Writer for VecWriter { } /// Encode the given value into a `Vec`. +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub fn encode_to_vec(val: E) -> Result, EncodeError> { encode_to_vec_with_config(val, config::Default) } /// Encode the given value into a `Vec` with the given `Config`. See the [config] module for more information. +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub fn encode_to_vec_with_config( val: E, config: C, @@ -271,6 +273,7 @@ where } } +#[cfg(feature = "atomic")] impl Decodable for Arc where T: Decodable, @@ -281,6 +284,7 @@ where } } +#[cfg(feature = "atomic")] impl Encodeable for Arc where T: Encodeable, diff --git a/src/features/impl_std.rs b/src/features/impl_std.rs index ee30a86..5c6f245 100644 --- a/src/features/impl_std.rs +++ b/src/features/impl_std.rs @@ -14,6 +14,7 @@ use std::{ }; /// Decode type `D` from the given reader. The reader can be any type that implements `std::io::Read`, e.g. `std::fs::File`. +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn decode_from(src: &mut R) -> Result { decode_from_with_config(src, config::Default) } @@ -21,6 +22,7 @@ pub fn decode_from(src: &mut R) -> Result( src: &mut R, _config: C, @@ -40,6 +42,7 @@ impl<'storage, R: std::io::Read> Reader<'storage> for R { } /// Encode the given value into any type that implements `std::io::Write`, e.g. `std::fs::File`. +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn encode_into_write( val: E, dst: &mut W, @@ -48,6 +51,7 @@ pub fn encode_into_write( } /// Encode the given value into any type that implements `std::io::Write`, e.g. `std::fs::File`, with the given `Config`. See the [config] module for more information. +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn encode_into_write_with_config( val: E, dst: &mut W, diff --git a/src/lib.rs b/src/lib.rs index 59e3dd7..3e066a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![warn(missing_docs)] +#![cfg_attr(docsrs, feature(doc_cfg))] //! Bincode is a crate for encoding and decoding using a tiny binary //! serialization strategy. Using it, you can easily go from having @@ -15,7 +16,8 @@ //! |Name |Default?|Supported types for Encodeable/Decodeable|Enabled methods |Other| //! |------|--------|-----------------------------------------|-----------------------------------------------------------------|-----| //! |std | Yes ||`decode_from[_with_config]` and `encode_into_write[_with_config]`| -//! |alloc | Yes |`Vec`, `HashMap`, `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `VecDeque`, `Box`, `Arc`, `Rc`, `Cow`|`encode_to_vec[_with_config]`| +//! |alloc | Yes |All common containers in alloc, like `Vec`, `String`, `Box`|`encode_to_vec[_with_config]`| +//! |atomic| Yes |All `Atomic*` integer types, e.g. `AtomicUsize`, and `AtomicBool`|| //! |derive| Yes |||Enables the `Encodeable` and `Decodeable` derive macro| //! |serde | No ||`serde_decode_from[_with_config]`, `serde_encode_into[_with_config]`|Also enables `_to_vec` when `alloc` is enabled| diff --git a/tests/alloc.rs b/tests/alloc.rs index 5f561b8..09c7edc 100644 --- a/tests/alloc.rs +++ b/tests/alloc.rs @@ -54,6 +54,7 @@ fn test_alloc_commons() { the_same(Cow::::Owned(5)); the_same(Cow::::Borrowed(&5)); the_same(Rc::::new(5)); + #[cfg(feature = "atomic")] the_same(Arc::::new(5)); the_same_with_comparer( {