Struct musli_wire::encoding::WireEncoding
source · [−]pub struct WireEncoding<I = Variable, L = Variable, const P: usize = MAX_INLINE_LEN> where
I: TypedIntegerEncoding,
L: TypedUsizeEncoding, { /* private fields */ }Expand description
Setting up encoding with parameters.
Implementations
sourceimpl WireEncoding<Variable, Variable, MAX_INLINE_LEN>
impl WireEncoding<Variable, Variable, MAX_INLINE_LEN>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct a new WireEncoding instance which uses Variable integer encoding.
You can modify this using the available factory methods:
use musli_wire::{WireEncoding, Fixed, Variable};
use musli::{Encode, Decode};
const CONFIG: WireEncoding<Fixed, Variable> = WireEncoding::new()
.with_fixed_integers();
#[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);sourceimpl<const P: usize, I, L> WireEncoding<I, L, P> where
I: TypedIntegerEncoding,
L: TypedUsizeEncoding,
impl<const P: usize, I, L> WireEncoding<I, L, P> where
I: TypedIntegerEncoding,
L: TypedUsizeEncoding,
sourcepub const fn with_variable_integers(self) -> WireEncoding<Variable, L, P>
pub const fn with_variable_integers(self) -> WireEncoding<Variable, L, P>
Configure the encoding to use variable integer encoding.
sourcepub const fn with_fixed_integers(self) -> WireEncoding<Fixed, L, P>
pub const fn with_fixed_integers(self) -> WireEncoding<Fixed, L, P>
Configure the encoding to use fixed integer encoding.
sourcepub const fn with_fixed_integers_le(
self
) -> WireEncoding<Fixed<LittleEndian>, L, P>
pub const fn with_fixed_integers_le(
self
) -> WireEncoding<Fixed<LittleEndian>, L, P>
Configure the encoding to use fixed integer little-endian encoding.
sourcepub const fn with_fixed_integers_be(
self
) -> WireEncoding<Fixed<BigEndian>, L, P>
pub const fn with_fixed_integers_be(
self
) -> WireEncoding<Fixed<BigEndian>, L, P>
Configure the encoding to use fixed integer big-endian encoding.
sourcepub const fn with_fixed_integers_ne(
self
) -> WireEncoding<Fixed<NetworkEndian>, L, P>
pub const fn with_fixed_integers_ne(
self
) -> WireEncoding<Fixed<NetworkEndian>, L, P>
Configure the encoding to use fixed integer network-endian encoding (Default).
sourcepub const fn with_variable_lengths(self) -> WireEncoding<I, Variable, P>
pub const fn with_variable_lengths(self) -> WireEncoding<I, Variable, P>
Configure the encoding to use variable length encoding.
sourcepub const fn with_fixed_lengths(self) -> WireEncoding<I, FixedLength<u32>, P>
pub const fn with_fixed_lengths(self) -> WireEncoding<I, FixedLength<u32>, P>
Configure the encoding to use fixed length 32-bit encoding when encoding lengths.
sourcepub const fn with_fixed_lengths64(self) -> WireEncoding<I, FixedLength<u64>, P>
pub const fn with_fixed_lengths64(self) -> WireEncoding<I, FixedLength<u64>, P>
Configure the encoding to use fixed length 64-bit encoding when encoding lengths.
sourcepub const fn with_max_pack<const N: usize>(self) -> WireEncoding<I, L, N>
pub const fn with_max_pack<const N: usize>(self) -> WireEncoding<I, L, N>
Modify the maximum pack sized allowwed in the wire format. This defaults to MAX_INLINE_LEN, a value that will fit unencoded in the Tag of the type.
sourcepub fn encode<W, T>(self, writer: W, value: &T) -> Result<(), W::Error> where
W: Writer,
T: ?Sized + Encode,
pub fn encode<W, T>(self, writer: W, value: &T) -> Result<(), W::Error> where
W: Writer,
T: ?Sized + Encode,
Encode the given value to the given Writer using the current configuration.
sourcepub fn to_writer<W, T>(self, write: W, value: &T) -> Result<(), Error> where
W: Write,
T: ?Sized + Encode,
pub fn to_writer<W, T>(self, write: W, value: &T) -> Result<(), Error> where
W: Write,
T: ?Sized + Encode,
Encode the given value to the given Write using the current configuration.
sourcepub fn to_vec<T>(self, value: &T) -> Result<Vec<u8>, VecWriterError> where
T: ?Sized + Encode,
pub fn to_vec<T>(self, value: &T) -> Result<Vec<u8>, VecWriterError> where
T: ?Sized + Encode,
Encode the given value to a Vec using the current configuration.
sourcepub fn to_fixed_bytes<const N: usize, T>(
self,
value: &T
) -> Result<FixedBytes<N>, FixedBytesWriterError> where
T: ?Sized + Encode,
pub fn to_fixed_bytes<const N: usize, T>(
self,
value: &T
) -> Result<FixedBytes<N>, FixedBytesWriterError> where
T: ?Sized + Encode,
Encode the given value to a fixed-size bytes using the current configuration.
sourcepub fn decode<'de, R, T>(self, reader: R) -> Result<T, R::Error> where
R: Reader<'de>,
T: Decode<'de>,
pub fn decode<'de, R, T>(self, reader: R) -> Result<T, R::Error> where
R: Reader<'de>,
T: Decode<'de>,
Decode the given type T from the given Reader using the current
configuration.
sourcepub fn from_slice<'de, T>(self, bytes: &'de [u8]) -> Result<T, SliceReaderError> where
T: Decode<'de>,
pub fn from_slice<'de, T>(self, bytes: &'de [u8]) -> Result<T, SliceReaderError> where
T: Decode<'de>,
Decode the given type T from the given slice using the current
configuration.
Trait Implementations
sourceimpl<I: Clone, L: Clone, const P: usize> Clone for WireEncoding<I, L, P> where
I: TypedIntegerEncoding,
L: TypedUsizeEncoding,
impl<I: Clone, L: Clone, const P: usize> Clone for WireEncoding<I, L, P> where
I: TypedIntegerEncoding,
L: TypedUsizeEncoding,
sourcefn clone(&self) -> WireEncoding<I, L, P>
fn clone(&self) -> WireEncoding<I, L, P>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
impl<I: Copy, L: Copy, const P: usize> Copy for WireEncoding<I, L, P> where
I: TypedIntegerEncoding,
L: TypedUsizeEncoding,
Auto Trait Implementations
impl<I, L, const P: usize> RefUnwindSafe for WireEncoding<I, L, P> where
I: RefUnwindSafe,
L: RefUnwindSafe,
impl<I, L, const P: usize> Send for WireEncoding<I, L, P> where
I: Send,
L: Send,
impl<I, L, const P: usize> Sync for WireEncoding<I, L, P> where
I: Sync,
L: Sync,
impl<I, L, const P: usize> Unpin for WireEncoding<I, L, P> where
I: Unpin,
L: Unpin,
impl<I, L, const P: usize> UnwindSafe for WireEncoding<I, L, P> where
I: UnwindSafe,
L: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more