mirror of https://git.sr.ht/~stygianentity/bincode
Added documentation for the src/featyres module
This commit is contained in:
parent
bb98b8fcbd
commit
7b85fc168e
|
|
@ -13,16 +13,18 @@ impl enc::write::Writer for VecWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encode the given value into a `Vec<u8>`.
|
||||||
pub fn encode_to_vec<E: enc::Encodeable>(val: E) -> Result<Vec<u8>, error::EncodeError> {
|
pub fn encode_to_vec<E: enc::Encodeable>(val: E) -> Result<Vec<u8>, error::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.
|
||||||
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,
|
||||||
) -> Result<Vec<u8>, error::EncodeError> {
|
) -> Result<Vec<u8>, error::EncodeError> {
|
||||||
let writer = VecWriter::default();
|
let writer = VecWriter::default();
|
||||||
let mut encoder = enc::Encoder::<_, C>::new(writer);
|
let mut encoder = enc::Encoder::<_, C>::new(writer, config);
|
||||||
val.encode(&mut encoder)?;
|
val.encode(&mut encoder)?;
|
||||||
Ok(encoder.into_writer().inner)
|
Ok(encoder.into_writer().inner)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,14 @@ use crate::{
|
||||||
error::{DecodeError, EncodeError},
|
error::{DecodeError, EncodeError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Decode type `D` from the given reader. The reader can be any type that implements `std::io::Read`, e.g. `std::fs::File`.
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
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,
|
||||||
|
|
@ -27,6 +31,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`.
|
||||||
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,
|
||||||
|
|
@ -34,16 +39,17 @@ pub fn encode_into_write<E: Encodeable, W: std::io::Write>(
|
||||||
encode_into_write_with_config(val, dst, config::Default)
|
encode_into_write_with_config(val, dst, config::Default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
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,
|
||||||
_config: C,
|
config: C,
|
||||||
) -> Result<usize, EncodeError> {
|
) -> Result<usize, EncodeError> {
|
||||||
let writer = IoWriter {
|
let writer = IoWriter {
|
||||||
writer: dst,
|
writer: dst,
|
||||||
bytes_written: 0,
|
bytes_written: 0,
|
||||||
};
|
};
|
||||||
let mut encoder = Encoder::<_, C>::new(writer);
|
let mut encoder = Encoder::<_, C>::new(writer, config);
|
||||||
val.encode(&mut encoder)?;
|
val.encode(&mut encoder)?;
|
||||||
Ok(encoder.into_writer().bytes_written)
|
Ok(encoder.into_writer().bytes_written)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue