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>
impl<T: PutBytes> Writer<T>
sourcepub fn new(target: T) -> Writer<T>
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.
sourcepub fn into_target(self) -> T
pub fn into_target(self) -> T
Consumes this Writer
, returning the underlying target.
sourcepub fn write_i8(&mut self, value: i8) -> Result<usize>
pub fn write_i8(&mut self, value: i8) -> Result<usize>
Appends an i8
value at the end of this writer.
sourcepub fn write_u8(&mut self, value: u8) -> Result<usize>
pub fn write_u8(&mut self, value: u8) -> Result<usize>
Appends an u8
value at the end of this writer.
sourcepub fn write_i16(&mut self, value: i16) -> Result<usize>
pub fn write_i16(&mut self, value: i16) -> Result<usize>
Appends an i16
value at the end of this writer.
sourcepub fn write_u16(&mut self, value: u16) -> Result<usize>
pub fn write_u16(&mut self, value: u16) -> Result<usize>
Appends an u16
value at the end of this writer.
sourcepub fn write_i32(&mut self, value: i32) -> Result<usize>
pub fn write_i32(&mut self, value: i32) -> Result<usize>
Appends an i32
value at the end of this writer.
sourcepub fn write_u32(&mut self, value: u32) -> Result<usize>
pub fn write_u32(&mut self, value: u32) -> Result<usize>
Appends an u32
value at the end of this writer.
sourcepub fn write_i64(&mut self, value: i64) -> Result<usize>
pub fn write_i64(&mut self, value: i64) -> Result<usize>
Appends an i64
value at the end of this writer.
sourcepub fn write_u64(&mut self, value: u64) -> Result<usize>
pub fn write_u64(&mut self, value: u64) -> Result<usize>
Appends an u64
value at the end of this writer.
sourcepub fn write_i128(&mut self, value: i128) -> Result<usize>
pub fn write_i128(&mut self, value: i128) -> Result<usize>
Appends an i128
value at the end of this writer.
sourcepub fn write_u128(&mut self, value: u128) -> Result<usize>
pub fn write_u128(&mut self, value: u128) -> Result<usize>
Appends an u128
value at the end of this writer.
sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> Result<usize>
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<usize>
Appends the given bytes
at the end of this writer.
Trait Implementations§
source§impl<'a, P: PutBytes> Serializer for &'a mut Writer<P>
impl<'a, P: PutBytes> Serializer for &'a mut Writer<P>
§type Ok = usize
type Ok = usize
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 SerializeSeq = StateSerializer<'a, P>
type SerializeSeq = StateSerializer<'a, P>
serialize_seq
for serializing the content of the
sequence.§type SerializeTuple = StateSerializer<'a, P>
type SerializeTuple = StateSerializer<'a, P>
serialize_tuple
for serializing the content of
the tuple.§type SerializeTupleStruct = StateSerializer<'a, P>
type SerializeTupleStruct = StateSerializer<'a, P>
serialize_tuple_struct
for serializing the
content of the tuple struct.§type SerializeTupleVariant = StateSerializer<'a, P>
type SerializeTupleVariant = StateSerializer<'a, P>
serialize_tuple_variant
for serializing the
content of the tuple variant.§type SerializeMap = StateSerializer<'a, P>
type SerializeMap = StateSerializer<'a, P>
serialize_map
for serializing the content of the
map.§type SerializeStruct = StateSerializer<'a, P>
type SerializeStruct = StateSerializer<'a, P>
serialize_struct
for serializing the content of
the struct.§type SerializeStructVariant = StateSerializer<'a, P>
type SerializeStructVariant = StateSerializer<'a, P>
serialize_struct_variant
for serializing the
content of the struct variant.source§fn serialize_bytes(self, v: &[u8]) -> Result<usize>
fn serialize_bytes(self, v: &[u8]) -> Result<usize>
source§fn serialize_unit_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str
) -> Result<usize>
fn serialize_unit_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str ) -> Result<usize>
source§fn serialize_newtype_struct<T: Serialize + ?Sized>(
self,
_name: &'static str,
value: &T
) -> Result<usize>
fn serialize_newtype_struct<T: Serialize + ?Sized>( self, _name: &'static str, value: &T ) -> Result<usize>
struct Millimeters(u8)
. Read moresource§fn serialize_newtype_variant<T: Serialize + ?Sized>(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
value: &T
) -> Result<usize>
fn serialize_newtype_variant<T: Serialize + ?Sized>( self, _name: &'static str, variant_index: u32, _variant: &'static str, value: &T ) -> Result<usize>
source§fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>
serialize_element
, then a call to
end
. Read moresource§fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple>
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple>
serialize_element
,
then a call to end
. Read moresource§fn serialize_tuple_struct(
self,
_name: &'static str,
_len: usize
) -> Result<Self::SerializeTupleStruct>
fn serialize_tuple_struct( self, _name: &'static str, _len: usize ) -> Result<Self::SerializeTupleStruct>
struct Rgb(u8, u8, u8)
. This
call must be followed by zero or more calls to serialize_field
, then a
call to end
. Read moresource§fn serialize_tuple_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
_len: usize
) -> Result<Self::SerializeTupleVariant>
fn serialize_tuple_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize ) -> Result<Self::SerializeTupleVariant>
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 moresource§fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>
serialize_key
and serialize_value
, then a call to end
. Read moresource§fn serialize_struct(
self,
_name: &'static str,
_len: usize
) -> Result<Self::SerializeStruct>
fn serialize_struct( self, _name: &'static str, _len: usize ) -> Result<Self::SerializeStruct>
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 moresource§fn serialize_struct_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
_len: usize
) -> Result<Self::SerializeStructVariant>
fn serialize_struct_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize ) -> Result<Self::SerializeStructVariant>
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 moresource§fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>
i128
value. Read moresource§fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>
u128
value. Read moresource§fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>where
I: IntoIterator,
<I as IntoIterator>::Item: Serialize,
fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>where I: IntoIterator, <I as IntoIterator>::Item: Serialize,
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)>,
fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>where K: Serialize, V: Serialize, I: IntoIterator<Item = (K, V)>,
source§fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>where
T: Display + ?Sized,
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>where T: Display + ?Sized,
Display
. Read moresource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Serialize
implementations should serialize in
human-readable form. Read more