Struct nuts_bytes::Writer

source ·
pub struct Writer<T> { /* private fields */ }
Expand description

A cursor like utility that writes structured data into an arbitrary target.

The target must implement the PutBytes trait which supports writing binary data into it.

Implementations§

source§

impl<T: PutBytes> Writer<T>

source

pub fn new(target: T) -> Writer<T>

Creates a new Writer instance.

The target, where the writer puts the binary data, is passed to the function. Every type, that implements the PutBytes trait can be the target of this writer.

source

pub fn serialize<S: Serialize>(&mut self, s: &S) -> Result<usize>

Serializes a data structure that implements Serde Serialize trait into this binary representation.

This is simply a wrapper for

s.serialize(self)
source

pub fn into_target(self) -> T

Consumes this Writer, returning the underlying target.

source

pub fn write_i8(&mut self, value: i8) -> Result<usize>

Appends an i8 value at the end of this writer.

source

pub fn write_u8(&mut self, value: u8) -> Result<usize>

Appends an u8 value at the end of this writer.

source

pub fn write_i16(&mut self, value: i16) -> Result<usize>

Appends an i16 value at the end of this writer.

source

pub fn write_u16(&mut self, value: u16) -> Result<usize>

Appends an u16 value at the end of this writer.

source

pub fn write_i32(&mut self, value: i32) -> Result<usize>

Appends an i32 value at the end of this writer.

source

pub fn write_u32(&mut self, value: u32) -> Result<usize>

Appends an u32 value at the end of this writer.

source

pub fn write_i64(&mut self, value: i64) -> Result<usize>

Appends an i64 value at the end of this writer.

source

pub fn write_u64(&mut self, value: u64) -> Result<usize>

Appends an u64 value at the end of this writer.

source

pub fn write_i128(&mut self, value: i128) -> Result<usize>

Appends an i128 value at the end of this writer.

source

pub fn write_u128(&mut self, value: u128) -> Result<usize>

Appends an u128 value at the end of this writer.

source

pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<usize>

Appends the given bytes at the end of this writer.

Trait Implementations§

source§

impl<T> AsRef<T> for Writer<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Debug> Debug for Writer<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, P: PutBytes> Serializer for &'a mut Writer<P>

§

type Ok = usize

The output type produced by this Serializer during successful serialization. Most serializers that produce text or binary output should set Ok = () and serialize into an io::Write or buffer contained within the Serializer instance. Serializers that build in-memory data structures may be simplified by using Ok to propagate the data structure around.
§

type Error = Error

The error type when some error occurs during serialization.
§

type SerializeSeq = StateSerializer<'a, P>

Type returned from serialize_seq for serializing the content of the sequence.
§

type SerializeTuple = StateSerializer<'a, P>

Type returned from serialize_tuple for serializing the content of the tuple.
§

type SerializeTupleStruct = StateSerializer<'a, P>

Type returned from serialize_tuple_struct for serializing the content of the tuple struct.
§

type SerializeTupleVariant = StateSerializer<'a, P>

Type returned from serialize_tuple_variant for serializing the content of the tuple variant.
§

type SerializeMap = StateSerializer<'a, P>

Type returned from serialize_map for serializing the content of the map.
§

type SerializeStruct = StateSerializer<'a, P>

Type returned from serialize_struct for serializing the content of the struct.
§

type SerializeStructVariant = StateSerializer<'a, P>

Type returned from serialize_struct_variant for serializing the content of the struct variant.
source§

fn serialize_bool(self, v: bool) -> Result<usize>

Serialize a bool value. Read more
source§

fn serialize_i8(self, v: i8) -> Result<usize>

Serialize an i8 value. Read more
source§

fn serialize_i16(self, v: i16) -> Result<usize>

Serialize an i16 value. Read more
source§

fn serialize_i32(self, v: i32) -> Result<usize>

Serialize an i32 value. Read more
source§

fn serialize_i64(self, v: i64) -> Result<usize>

Serialize an i64 value. Read more
source§

fn serialize_u8(self, v: u8) -> Result<usize>

Serialize a u8 value. Read more
source§

fn serialize_u16(self, v: u16) -> Result<usize>

Serialize a u16 value. Read more
source§

fn serialize_u32(self, v: u32) -> Result<usize>

Serialize a u32 value. Read more
source§

fn serialize_u64(self, v: u64) -> Result<usize>

Serialize a u64 value. Read more
source§

fn serialize_f32(self, _v: f32) -> Result<usize>

Serialize an f32 value. Read more
source§

fn serialize_f64(self, _v: f64) -> Result<usize>

Serialize an f64 value. Read more
source§

fn serialize_char(self, v: char) -> Result<usize>

Serialize a character. Read more
source§

fn serialize_str(self, v: &str) -> Result<usize>

Serialize a &str. Read more
source§

fn serialize_bytes(self, v: &[u8]) -> Result<usize>

Serialize a chunk of raw byte data. Read more
source§

fn serialize_none(self) -> Result<usize>

Serialize a None value. Read more
source§

fn serialize_some<T: Serialize + ?Sized>(self, value: &T) -> Result<usize>

Serialize a Some(T) value. Read more
source§

fn serialize_unit(self) -> Result<usize>

Serialize a () value. Read more
source§

fn serialize_unit_struct(self, _name: &'static str) -> Result<usize>

Serialize a unit struct like struct Unit or PhantomData<T>. Read more
source§

fn serialize_unit_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str ) -> Result<usize>

Serialize a unit variant like E::A in enum E { A, B }. Read more
source§

fn serialize_newtype_struct<T: Serialize + ?Sized>( self, _name: &'static str, value: &T ) -> Result<usize>

Serialize a newtype struct like struct Millimeters(u8). Read more
source§

fn serialize_newtype_variant<T: Serialize + ?Sized>( self, _name: &'static str, variant_index: u32, _variant: &'static str, value: &T ) -> Result<usize>

Serialize a newtype variant like E::N in enum E { N(u8) }. Read more
source§

fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>

Begin to serialize a variably sized sequence. This call must be followed by zero or more calls to serialize_element, then a call to end. Read more
source§

fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple>

Begin to serialize a statically sized sequence whose length will be known at deserialization time without looking at the serialized data. This call must be followed by zero or more calls to serialize_element, then a call to end. Read more
source§

fn serialize_tuple_struct( self, _name: &'static str, _len: usize ) -> Result<Self::SerializeTupleStruct>

Begin to serialize a tuple struct like struct Rgb(u8, u8, u8). This call must be followed by zero or more calls to serialize_field, then a call to end. Read more
source§

fn serialize_tuple_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize ) -> Result<Self::SerializeTupleVariant>

Begin to serialize a tuple variant like E::T in enum E { T(u8, u8) }. This call must be followed by zero or more calls to serialize_field, then a call to end. Read more
source§

fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>

Begin to serialize a map. This call must be followed by zero or more calls to serialize_key and serialize_value, then a call to end. Read more
source§

fn serialize_struct( self, _name: &'static str, _len: usize ) -> Result<Self::SerializeStruct>

Begin to serialize a struct like struct Rgb { r: u8, g: u8, b: u8 }. This call must be followed by zero or more calls to serialize_field, then a call to end. Read more
source§

fn serialize_struct_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize ) -> Result<Self::SerializeStructVariant>

Begin to serialize a struct variant like E::S in enum E { S { r: u8, g: u8, b: u8 } }. This call must be followed by zero or more calls to serialize_field, then a call to end. Read more
source§

fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>

Serialize an i128 value. Read more
source§

fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>

Serialize a u128 value. Read more
source§

fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>where I: IntoIterator, <I as IntoIterator>::Item: Serialize,

Collect an iterator as a sequence. Read more
source§

fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>where K: Serialize, V: Serialize, I: IntoIterator<Item = (K, V)>,

Collect an iterator as a map. Read more
source§

fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>where T: Display + ?Sized,

Serialize a string produced by an implementation of Display. Read more
source§

fn is_human_readable(&self) -> bool

Determine whether Serialize implementations should serialize in human-readable form. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Writer<T>where T: RefUnwindSafe,

§

impl<T> Send for Writer<T>where T: Send,

§

impl<T> Sync for Writer<T>where T: Sync,

§

impl<T> Unpin for Writer<T>where T: Unpin,

§

impl<T> UnwindSafe for Writer<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.