pub struct Encoding<M = DefaultMode> { /* private fields */ }Expand description
Setting up encoding with parameters.
Implementations§
Source§impl Encoding
impl Encoding
Sourcepub const fn new() -> Encoding
pub const fn new() -> Encoding
Construct a new Encoding instance.
use musli_descriptive::{Encoding};
use musli::{Encode, Decode};
use musli::mode::DefaultMode;
const CONFIG: Encoding<DefaultMode> = Encoding::new();
#[derive(Debug, PartialEq, Encode, Decode)]
struct Struct<'a> {
name: &'a str,
age: u32,
}
let mut out = Vec::new();
let expected = Struct {
name: "Aristotle",
age: 61,
};
CONFIG.encode(&mut out, &expected)?;
let actual = CONFIG.decode(&out[..])?;
assert_eq!(expected, actual);Source§impl<M> Encoding<M>where
M: Mode,
impl<M> Encoding<M>where
M: Mode,
Sourcepub fn encode_with<C, W, T>(
self,
cx: &mut C,
writer: W,
value: &T,
) -> Result<(), <C as Context>::Error>
pub fn encode_with<C, W, T>( self, cx: &mut C, writer: W, value: &T, ) -> Result<(), <C as Context>::Error>
Encode the given value to the given Writer using the current
configuration.
This is the same as Encoding::encode but allows for using a
configurable Context.
Sourcepub fn decode_with<'de, C, R, T>(
self,
cx: &mut C,
reader: R,
) -> Result<T, <C as Context>::Error>
pub fn decode_with<'de, C, R, T>( self, cx: &mut C, reader: R, ) -> Result<T, <C as Context>::Error>
Decode the given type T from the given Reader using the current
configuration.
This is the same as Encoding::decode but allows for using a
configurable Context.
Sourcepub fn decode<'de, R, T>(self, reader: R) -> Result<T, Error>
pub fn decode<'de, R, T>(self, reader: R) -> Result<T, Error>
Decode the given type T from the given Reader using the current
configuration.
Sourcepub fn encode<W, T>(self, writer: W, value: &T) -> Result<(), Error>
pub fn encode<W, T>(self, writer: W, value: &T) -> Result<(), Error>
Encode the given value to the given Writer using the current configuration.
Sourcepub fn to_vec<T>(self, value: &T) -> Result<Vec<u8>, Error>
pub fn to_vec<T>(self, value: &T) -> Result<Vec<u8>, Error>
Encode the given value to a Vec using the current configuration.
Sourcepub fn to_vec_with<C, T>(
self,
cx: &mut C,
value: &T,
) -> Result<Vec<u8>, <C as Context>::Error>
pub fn to_vec_with<C, T>( self, cx: &mut C, value: &T, ) -> Result<Vec<u8>, <C as Context>::Error>
Encode the given value to a Vec using the current configuration.
This is the same as Encoding::to_vec, but allows for using a
configurable Context.
Sourcepub fn to_fixed_bytes<const N: usize, T>(
self,
value: &T,
) -> Result<FixedBytes<N>, Error>
pub fn to_fixed_bytes<const N: usize, T>( self, value: &T, ) -> Result<FixedBytes<N>, Error>
Encode the given value to a fixed-size bytes using the current configuration.
Sourcepub fn to_fixed_bytes_with<C, const N: usize, T>(
self,
cx: &mut C,
value: &T,
) -> Result<FixedBytes<N>, <C as Context>::Error>
pub fn to_fixed_bytes_with<C, const N: usize, T>( self, cx: &mut C, value: &T, ) -> Result<FixedBytes<N>, <C as Context>::Error>
Encode the given value to a fixed-size bytes using the current configuration.