From e140c2b5c5bb5abab7fcc6a9d4540aaa3bf566a6 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 28 Jan 2017 23:52:52 +0100 Subject: Use void for the unreachable serializers --- src/ser/part.rs | 174 ++++++++++++-------------------------------------------- 1 file changed, 36 insertions(+), 138 deletions(-) (limited to 'src/ser/part.rs') diff --git a/src/ser/part.rs b/src/ser/part.rs index a865450..097504e 100644 --- a/src/ser/part.rs +++ b/src/ser/part.rs @@ -1,4 +1,5 @@ use ser::Error; +use ser::void::VoidSerializer; use serde::ser; use std::str; @@ -36,13 +37,13 @@ pub trait Sink: Sized { impl ser::Serializer for PartSerializer { type Ok = S::Ok; type Error = Error; - type SerializeSeq = Self; - type SerializeTuple = Self; - type SerializeTupleStruct = Self; - type SerializeTupleVariant = Self; - type SerializeMap = Self; - type SerializeStruct = Self; - type SerializeStructVariant = Self; + type SerializeSeq = VoidSerializer; + type SerializeTuple = VoidSerializer; + type SerializeTupleStruct = VoidSerializer; + type SerializeTupleVariant = VoidSerializer; + type SerializeMap = VoidSerializer; + type SerializeStruct = VoidSerializer; + type SerializeStructVariant = VoidSerializer; fn serialize_bool(self, v: bool) -> Result { self.sink.serialize_bool(v) @@ -147,165 +148,62 @@ impl ser::Serializer for PartSerializer { self.sink.serialize_some(value) } - fn serialize_seq(self, _len: Option) -> Result { + fn serialize_seq(self, + _len: Option) + -> Result { Err(self.sink.unsupported()) } - fn serialize_seq_fixed_size(self, _len: usize) -> Result { + fn serialize_seq_fixed_size(self, + _len: usize) + -> Result { Err(self.sink.unsupported()) } - fn serialize_tuple(self, _len: usize) -> Result { + fn serialize_tuple(self, + _len: usize) + -> Result { Err(self.sink.unsupported()) } fn serialize_tuple_struct(self, _name: &'static str, _len: usize) - -> Result { + -> Result { Err(self.sink.unsupported()) } - fn serialize_tuple_variant(self, - _name: &'static str, - _variant_index: usize, - _variant: &'static str, - _len: usize) - -> Result { + fn serialize_tuple_variant + (self, + _name: &'static str, + _variant_index: usize, + _variant: &'static str, + _len: usize) + -> Result { Err(self.sink.unsupported()) } - fn serialize_map(self, _len: Option) -> Result { + fn serialize_map(self, + _len: Option) + -> Result { Err(self.sink.unsupported()) } fn serialize_struct(self, _name: &'static str, _len: usize) - -> Result { + -> Result { Err(self.sink.unsupported()) } - fn serialize_struct_variant(self, - _name: &'static str, - _variant_index: usize, - _variant: &'static str, - _len: usize) - -> Result { + fn serialize_struct_variant + (self, + _name: &'static str, + _variant_index: usize, + _variant: &'static str, + _len: usize) + -> Result { Err(self.sink.unsupported()) } } - -impl ser::SerializeSeq for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_element(&mut self, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - -impl ser::SerializeTuple for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_element(&mut self, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - -impl ser::SerializeTupleStruct for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_field(&mut self, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - -impl ser::SerializeTupleVariant for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_field(&mut self, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - -impl ser::SerializeMap for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_key(&mut self, - _key: &T) - -> Result<(), Error> { - unreachable!() - } - - fn serialize_value(&mut self, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - -impl ser::SerializeStruct for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_field(&mut self, - _key: &'static str, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - -impl ser::SerializeStructVariant for PartSerializer { - type Ok = S::Ok; - type Error = Error; - - fn serialize_field(&mut self, - _key: &'static str, - _value: &T) - -> Result<(), Error> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} -- cgit v1.2.3