mirror of https://git.sr.ht/~stygianentity/bincode
Added badges to the functions to indicate which features they require
This commit is contained in:
parent
1f261cede3
commit
61c1e8a7cd
|
|
@ -38,3 +38,8 @@ serde = { version = "1.0.130", optional = true }
|
||||||
serde_derive = "1.0.130"
|
serde_derive = "1.0.130"
|
||||||
serde_json = "1.0.68"
|
serde_json = "1.0.68"
|
||||||
tempfile = "3.2.0"
|
tempfile = "3.2.0"
|
||||||
|
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
|
||||||
pub use bincode_derive::{Decodable, Encodable};
|
pub use bincode_derive::{Decodable, Encodable};
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,13 @@ impl enc::write::Writer for VecWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encode the given value into a `Vec<u8>`.
|
/// 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> {
|
pub fn encode_to_vec<E: enc::Encodeable>(val: E) -> Result<Vec<u8>, EncodeError> {
|
||||||
encode_to_vec_with_config(val, config::Default)
|
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.
|
/// 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>(
|
pub fn encode_to_vec_with_config<E: enc::Encodeable, C: Config>(
|
||||||
val: E,
|
val: E,
|
||||||
config: C,
|
config: C,
|
||||||
|
|
@ -271,6 +273,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "atomic")]
|
||||||
impl<T> Decodable for Arc<T>
|
impl<T> Decodable for Arc<T>
|
||||||
where
|
where
|
||||||
T: Decodable,
|
T: Decodable,
|
||||||
|
|
@ -281,6 +284,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "atomic")]
|
||||||
impl<T> Encodeable for Arc<T>
|
impl<T> Encodeable for Arc<T>
|
||||||
where
|
where
|
||||||
T: Encodeable,
|
T: Encodeable,
|
||||||
|
|
|
||||||
|
|
@ -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`.
|
/// 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> {
|
pub fn decode_from<D: Decodable, R: std::io::Read>(src: &mut R) -> Result<D, DecodeError> {
|
||||||
decode_from_with_config(src, config::Default)
|
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`.
|
/// 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.
|
/// 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>(
|
pub fn decode_from_with_config<D: Decodable, C: Config, R: std::io::Read>(
|
||||||
src: &mut R,
|
src: &mut R,
|
||||||
_config: C,
|
_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`.
|
/// 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>(
|
pub fn encode_into_write<E: Encodeable, W: std::io::Write>(
|
||||||
val: E,
|
val: E,
|
||||||
dst: &mut W,
|
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.
|
/// 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>(
|
pub fn encode_into_write_with_config<E: Encodeable, C: Config, W: std::io::Write>(
|
||||||
val: E,
|
val: E,
|
||||||
dst: &mut W,
|
dst: &mut W,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
//! Bincode is a crate for encoding and decoding using a tiny binary
|
//! Bincode is a crate for encoding and decoding using a tiny binary
|
||||||
//! serialization strategy. Using it, you can easily go from having
|
//! serialization strategy. Using it, you can easily go from having
|
||||||
|
|
@ -15,7 +16,8 @@
|
||||||
//! |Name |Default?|Supported types for Encodeable/Decodeable|Enabled methods |Other|
|
//! |Name |Default?|Supported types for Encodeable/Decodeable|Enabled methods |Other|
|
||||||
//! |------|--------|-----------------------------------------|-----------------------------------------------------------------|-----|
|
//! |------|--------|-----------------------------------------|-----------------------------------------------------------------|-----|
|
||||||
//! |std | Yes ||`decode_from[_with_config]` and `encode_into_write[_with_config]`|
|
//! |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|
|
//! |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|
|
//! |serde | No ||`serde_decode_from[_with_config]`, `serde_encode_into[_with_config]`|Also enables `_to_vec` when `alloc` is enabled|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ fn test_alloc_commons() {
|
||||||
the_same(Cow::<u32>::Owned(5));
|
the_same(Cow::<u32>::Owned(5));
|
||||||
the_same(Cow::<u32>::Borrowed(&5));
|
the_same(Cow::<u32>::Borrowed(&5));
|
||||||
the_same(Rc::<u32>::new(5));
|
the_same(Rc::<u32>::new(5));
|
||||||
|
#[cfg(feature = "atomic")]
|
||||||
the_same(Arc::<u32>::new(5));
|
the_same(Arc::<u32>::new(5));
|
||||||
the_same_with_comparer(
|
the_same_with_comparer(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue