From bc8197c884e7a5dae25b6aedb02eac98145bee92 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 31 Jan 2017 10:42:51 +0100 Subject: Update serde to 0.9.3 and use serde::ser::Impossible --- src/lib.rs | 3 +- src/ser/mod.rs | 9 ++--- src/ser/pair.rs | 49 ++++++++++++----------- src/ser/part.rs | 19 +++++---- src/ser/void.rs | 122 -------------------------------------------------------- 5 files changed, 40 insertions(+), 162 deletions(-) delete mode 100644 src/ser/void.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 8fefd77..285a091 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,12 @@ //! `x-www-form-urlencoded` meets Serde +#![warn(unused_extern_crates)] + extern crate itoa; extern crate dtoa; #[macro_use] extern crate serde; extern crate url; -extern crate void; pub mod de; pub mod ser; diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 50355fd..f36be4f 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -4,7 +4,6 @@ mod key; mod pair; mod part; mod value; -mod void; use serde::ser; use std::borrow::Cow; @@ -102,21 +101,21 @@ pub struct SeqSerializer<'output, Target: 'output + UrlEncodedTarget> { /// /// Never instantiated, tuples are not supported at top-level. pub struct TupleSerializer<'output, T: 'output + UrlEncodedTarget> { - inner: void::VoidSerializer<&'output mut UrlEncodedSerializer>, + inner: ser::Impossible<&'output mut UrlEncodedSerializer, Error>, } /// Tuple struct serializer. /// /// Never instantiated, tuple structs are not supported. pub struct TupleStructSerializer<'output, T: 'output + UrlEncodedTarget> { - inner: void::VoidSerializer<&'output mut UrlEncodedSerializer>, + inner: ser::Impossible<&'output mut UrlEncodedSerializer, Error>, } /// Tuple variant serializer. /// /// Never instantiated, tuple variants are not supported. pub struct TupleVariantSerializer<'output, T: 'output + UrlEncodedTarget> { - inner: void::VoidSerializer<&'output mut UrlEncodedSerializer>, + inner: ser::Impossible<&'output mut UrlEncodedSerializer, Error>, } /// Map serializer. @@ -134,7 +133,7 @@ pub struct StructSerializer<'output, Target: 'output + UrlEncodedTarget> { /// /// Never instantiated, struct variants are not supported. pub struct StructVariantSerializer<'output, T: 'output + UrlEncodedTarget> { - inner: void::VoidSerializer<&'output mut UrlEncodedSerializer>, + inner: ser::Impossible<&'output mut UrlEncodedSerializer, Error>, } impl<'output, Target> ser::Serializer for Serializer<'output, Target> diff --git a/src/ser/pair.rs b/src/ser/pair.rs index 743b3dd..6815647 100644 --- a/src/ser/pair.rs +++ b/src/ser/pair.rs @@ -2,7 +2,6 @@ use ser::Error; use ser::key::KeySink; use ser::part::PartSerializer; use ser::value::ValueSink; -use ser::void::VoidSerializer; use serde::ser; use std::borrow::Cow; use std::mem; @@ -30,13 +29,13 @@ impl<'target, Target> ser::Serializer for PairSerializer<'target, Target> { type Ok = (); type Error = Error; - type SerializeSeq = VoidSerializer<()>; + type SerializeSeq = ser::Impossible<(), Error>; type SerializeTuple = Self; - type SerializeTupleStruct = VoidSerializer<()>; - type SerializeTupleVariant = VoidSerializer<()>; - type SerializeMap = VoidSerializer<()>; - type SerializeStruct = VoidSerializer<()>; - type SerializeStructVariant = VoidSerializer<()>; + type SerializeTupleStruct = ser::Impossible<(), Error>; + type SerializeTupleVariant = ser::Impossible<(), Error>; + type SerializeMap = ser::Impossible<(), Error>; + type SerializeStruct = ser::Impossible<(), Error>; + type SerializeStructVariant = ser::Impossible<(), Error>; fn serialize_bool(self, _v: bool) -> Result<(), Error> { Err(Error::unsupported_pair()) @@ -140,13 +139,13 @@ impl<'target, Target> ser::Serializer for PairSerializer<'target, Target> fn serialize_seq(self, _len: Option) - -> Result, Error> { + -> Result { Err(Error::unsupported_pair()) } fn serialize_seq_fixed_size(self, _len: usize) - -> Result, Error> { + -> Result { Err(Error::unsupported_pair()) } @@ -161,38 +160,40 @@ impl<'target, Target> ser::Serializer for PairSerializer<'target, Target> fn serialize_tuple_struct(self, _name: &'static str, _len: usize) - -> Result, Error> { + -> Result { Err(Error::unsupported_pair()) } - fn serialize_tuple_variant(self, - _name: &'static str, - _variant_index: usize, - _variant: &'static str, - _len: usize) - -> Result, Error> { + fn serialize_tuple_variant + (self, + _name: &'static str, + _variant_index: usize, + _variant: &'static str, + _len: usize) + -> Result { Err(Error::unsupported_pair()) } fn serialize_map(self, _len: Option) - -> Result, Error> { + -> Result { Err(Error::unsupported_pair()) } fn serialize_struct(self, _name: &'static str, _len: usize) - -> Result, Error> { + -> Result { Err(Error::unsupported_pair()) } - fn serialize_struct_variant(self, - _name: &'static str, - _variant_index: usize, - _variant: &'static str, - _len: usize) - -> Result, Error> { + fn serialize_struct_variant + (self, + _name: &'static str, + _variant_index: usize, + _variant: &'static str, + _len: usize) + -> Result { Err(Error::unsupported_pair()) } } diff --git a/src/ser/part.rs b/src/ser/part.rs index e720314..42653c0 100644 --- a/src/ser/part.rs +++ b/src/ser/part.rs @@ -1,7 +1,6 @@ use dtoa; use itoa; use ser::Error; -use ser::void::VoidSerializer; use serde::ser; use std::str; @@ -37,13 +36,13 @@ pub trait Sink: Sized { impl ser::Serializer for PartSerializer { type Ok = S::Ok; type Error = Error; - type SerializeSeq = VoidSerializer; - type SerializeTuple = VoidSerializer; - type SerializeTupleStruct = VoidSerializer; - type SerializeTupleVariant = VoidSerializer; - type SerializeMap = VoidSerializer; - type SerializeStruct = VoidSerializer; - type SerializeStructVariant = VoidSerializer; + type SerializeSeq = ser::Impossible; + type SerializeTuple = ser::Impossible; + type SerializeTupleStruct = ser::Impossible; + type SerializeTupleVariant = ser::Impossible; + type SerializeMap = ser::Impossible; + type SerializeStruct = ser::Impossible; + type SerializeStructVariant = ser::Impossible; fn serialize_bool(self, v: bool) -> Result { self.sink.serialize_static_str(if v { "true" } else { "false" }) @@ -210,7 +209,7 @@ impl ser::Serializer for PartSerializer { impl PartSerializer { fn serialize_integer(self, value: I) -> Result - where I: itoa::Integer + where I: itoa::Integer, { let mut buf = [b'\0'; 20]; let len = itoa::write(&mut buf[..], value).unwrap(); @@ -219,7 +218,7 @@ impl PartSerializer { } fn serialize_floating(self, value: F) -> Result - where F: dtoa::Floating + where F: dtoa::Floating, { let mut buf = [b'\0'; 24]; let len = dtoa::write(&mut buf[..], value).unwrap(); diff --git a/src/ser/void.rs b/src/ser/void.rs deleted file mode 100644 index 4765bb7..0000000 --- a/src/ser/void.rs +++ /dev/null @@ -1,122 +0,0 @@ -use ser::Error; -use serde::ser; -use std::marker::PhantomData; -use void; - -pub struct VoidSerializer { - void: void::Void, - _marker: PhantomData, -} - -impl ser::SerializeSeq for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_element(&mut self, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} - -impl ser::SerializeTuple for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_element(&mut self, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} - -impl ser::SerializeTupleStruct for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_field(&mut self, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} - -impl ser::SerializeTupleVariant for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_field(&mut self, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} - -impl ser::SerializeMap for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_key(&mut self, - _key: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn serialize_value(&mut self, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} - -impl ser::SerializeStruct for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_field(&mut self, - _key: &'static str, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} - -impl ser::SerializeStructVariant for VoidSerializer { - type Ok = Ok; - type Error = Error; - - fn serialize_field(&mut self, - _key: &'static str, - _value: &T) - -> Result<(), Error> { - void::unreachable(self.void) - } - - fn end(self) -> Result { - void::unreachable(self.void) - } -} -- cgit v1.2.3