Exact

Struct Exact 

Source
pub struct Exact;
Expand description

Encode a given numeric value exactly using its native format.

This does not minimise or convert, so the value is written as is.

§Examples

u8 is encoded to positive fixint or uint 8

use serde::Serialize;
use messagepack_serde::ser::{to_slice_with_config, Exact};

let mut buf = [0_u8;1];
to_slice_with_config(&1_u8, &mut buf, Exact).unwrap();

let expected = [1_u8]; // 1 encoded in `positive fixint`
assert_eq!(buf,expected);

u16 is encoded to uint 16

use serde::Serialize;
use messagepack_serde::ser::{to_slice_with_config, Exact};

let mut buf = [0_u8;3];
to_slice_with_config(&1_u16, &mut buf, Exact).unwrap();

let expected = [0xcd_u8, 0x00_u8, 1_u8]; // 1 encoded in `uint 16`
assert_eq!(buf,expected);

Trait Implementations§

Source§

impl<W: IoWrite> NumEncoder<W> for Exact

Source§

fn encode_i8( v: i8, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode i8
Source§

fn encode_i16( v: i16, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode i16
Source§

fn encode_i32( v: i32, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode i32
Source§

fn encode_i64( v: i64, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode i64
Source§

fn encode_i128( v: i128, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode i128
Source§

fn encode_u8( v: u8, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode u8
Source§

fn encode_u16( v: u16, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode u16
Source§

fn encode_u32( v: u32, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode u32
Source§

fn encode_u64( v: u64, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode u64
Source§

fn encode_u128( v: u128, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode u128
Source§

fn encode_f32( v: f32, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode f32
Source§

fn encode_f64( v: f64, writer: &mut W, ) -> Result<usize, Error<<W as IoWrite>::Error>>

decide encode f64

Auto Trait Implementations§

§

impl Freeze for Exact

§

impl RefUnwindSafe for Exact

§

impl Send for Exact

§

impl Sync for Exact

§

impl Unpin for Exact

§

impl UnwindSafe for Exact

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> 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, 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.