Encoding

Struct Encoding 

Source
pub struct Encoding<M = DefaultMode> { /* private fields */ }
Expand description

Setting up encoding with parameters.

Implementations§

Source§

impl Encoding

Source

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,

Source

pub const fn with_mode<T>(self) -> Encoding<T>
where T: Mode,

Change the mode of the encoding.

Source

pub fn encode_with<C, W, T>( self, cx: &mut C, writer: W, value: &T, ) -> Result<(), <C as Context>::Error>
where C: Context<Input = Error>, W: Writer, Error: From<<W as Writer>::Error>, T: Encode<M> + ?Sized,

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.

Source

pub fn decode_with<'de, C, R, T>( self, cx: &mut C, reader: R, ) -> Result<T, <C as Context>::Error>
where C: Context<Input = Error>, R: Reader<'de>, Error: From<<R as Reader<'de>>::Error>, T: Decode<'de, M>,

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.

Source

pub fn decode<'de, R, T>(self, reader: R) -> Result<T, Error>
where R: Reader<'de>, Error: From<<R as Reader<'de>>::Error>, T: Decode<'de, M>,

Decode the given type T from the given Reader using the current configuration.

Source

pub fn encode<W, T>(self, writer: W, value: &T) -> Result<(), Error>
where W: Writer, Error: From<<W as Writer>::Error>, T: Encode<M> + ?Sized,

Encode the given value to the given Writer using the current configuration.

Source

pub fn to_vec<T>(self, value: &T) -> Result<Vec<u8>, Error>
where T: Encode<M> + ?Sized,

Encode the given value to a Vec using the current configuration.

Source

pub fn to_vec_with<C, T>( self, cx: &mut C, value: &T, ) -> Result<Vec<u8>, <C as Context>::Error>
where C: Context<Input = Error>, T: Encode<M> + ?Sized,

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.

Source

pub fn to_fixed_bytes<const N: usize, T>( self, value: &T, ) -> Result<FixedBytes<N>, Error>
where T: Encode<M> + ?Sized,

Encode the given value to a fixed-size bytes using the current configuration.

Source

pub fn to_fixed_bytes_with<C, const N: usize, T>( self, cx: &mut C, value: &T, ) -> Result<FixedBytes<N>, <C as Context>::Error>
where C: Context<Input = Error>, T: Encode<M> + ?Sized,

Encode the given value to a fixed-size bytes using the current configuration.

Source

pub fn from_slice<'de, T>(self, bytes: &'de [u8]) -> Result<T, Error>
where T: Decode<'de, M>,

Decode the given type T from the given slice using the current configuration.

Trait Implementations§

Source§

impl<M> Clone for Encoding<M>
where M: Mode,

Source§

fn clone(&self) -> Encoding<M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Copy for Encoding<M>
where M: Mode,

Auto Trait Implementations§

§

impl<M> Freeze for Encoding<M>

§

impl<M> RefUnwindSafe for Encoding<M>
where M: RefUnwindSafe,

§

impl<M> Send for Encoding<M>
where M: Send,

§

impl<M> Sync for Encoding<M>
where M: Sync,

§

impl<M> Unpin for Encoding<M>
where M: Unpin,

§

impl<M> UnwindSafe for Encoding<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V