Added badges to the functions to indicate which features they require

This commit is contained in:
Victor Koenders 2021-10-17 15:00:14 +02:00
parent 1f261cede3
commit 61c1e8a7cd
6 changed files with 18 additions and 1 deletions

View File

@ -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"]

View File

@ -1 +1,2 @@
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub use bincode_derive::{Decodable, Encodable};

View File

@ -20,11 +20,13 @@ impl enc::write::Writer for VecWriter {
}
/// Encode the given value into a `Vec<u8>`.
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn encode_to_vec<E: enc::Encodeable>(val: E) -> Result<Vec<u8>, EncodeError> {
encode_to_vec_with_config(val, config::Default)
}
/// Encode the given value into a `Vec<u8>` 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<E: enc::Encodeable, C: Config>(
val: E,
config: C,
@ -271,6 +273,7 @@ where
}
}
#[cfg(feature = "atomic")]
impl<T> Decodable for Arc<T>
where
T: Decodable,
@ -281,6 +284,7 @@ where
}
}
#[cfg(feature = "atomic")]
impl<T> Encodeable for Arc<T>
where
T: Encodeable,

View File

@ -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<D: Decodable, R: std::io::Read>(src: &mut R) -> Result<D, DecodeError> {
decode_from_with_config(src, config::Default)
}
@ -21,6 +22,7 @@ pub fn decode_from<D: Decodable, R: std::io::Read>(src: &mut R) -> Result<D, Dec
/// Decode type `D` from the given reader with the given `Config`. The reader can be any type that implements `std::io::Read`, e.g. `std::fs::File`.
///
/// See the [config] module for more information about config options.
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn decode_from_with_config<D: Decodable, C: Config, R: std::io::Read>(
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<E: Encodeable, W: std::io::Write>(
val: E,
dst: &mut W,
@ -48,6 +51,7 @@ pub fn encode_into_write<E: Encodeable, W: std::io::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<E: Encodeable, C: Config, W: std::io::Write>(
val: E,
dst: &mut W,

View File

@ -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|

View File

@ -54,6 +54,7 @@ fn test_alloc_commons() {
the_same(Cow::<u32>::Owned(5));
the_same(Cow::<u32>::Borrowed(&5));
the_same(Rc::<u32>::new(5));
#[cfg(feature = "atomic")]
the_same(Arc::<u32>::new(5));
the_same_with_comparer(
{