Update serde to 0.9.3 and use serde::ser::Impossible
This commit is contained in:
parent
2cc32847ac
commit
bc8197c884
@ -14,6 +14,5 @@ test = false
|
||||
[dependencies]
|
||||
dtoa = "0.4.0"
|
||||
itoa = "0.3.0"
|
||||
serde = "0.9.2"
|
||||
serde = "0.9.3"
|
||||
url = "1.0.0"
|
||||
void = "1.0.2"
|
||||
|
@ -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;
|
||||
|
@ -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<T>>,
|
||||
inner: ser::Impossible<&'output mut UrlEncodedSerializer<T>, Error>,
|
||||
}
|
||||
|
||||
/// Tuple struct serializer.
|
||||
///
|
||||
/// Never instantiated, tuple structs are not supported.
|
||||
pub struct TupleStructSerializer<'output, T: 'output + UrlEncodedTarget> {
|
||||
inner: void::VoidSerializer<&'output mut UrlEncodedSerializer<T>>,
|
||||
inner: ser::Impossible<&'output mut UrlEncodedSerializer<T>, Error>,
|
||||
}
|
||||
|
||||
/// Tuple variant serializer.
|
||||
///
|
||||
/// Never instantiated, tuple variants are not supported.
|
||||
pub struct TupleVariantSerializer<'output, T: 'output + UrlEncodedTarget> {
|
||||
inner: void::VoidSerializer<&'output mut UrlEncodedSerializer<T>>,
|
||||
inner: ser::Impossible<&'output mut UrlEncodedSerializer<T>, 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<T>>,
|
||||
inner: ser::Impossible<&'output mut UrlEncodedSerializer<T>, Error>,
|
||||
}
|
||||
|
||||
impl<'output, Target> ser::Serializer for Serializer<'output, Target>
|
||||
|
@ -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<usize>)
|
||||
-> Result<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeSeq, Error> {
|
||||
Err(Error::unsupported_pair())
|
||||
}
|
||||
|
||||
fn serialize_seq_fixed_size(self,
|
||||
_len: usize)
|
||||
-> Result<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeSeq, Error> {
|
||||
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<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeTupleStruct, Error> {
|
||||
Err(Error::unsupported_pair())
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(self,
|
||||
fn serialize_tuple_variant
|
||||
(self,
|
||||
_name: &'static str,
|
||||
_variant_index: usize,
|
||||
_variant: &'static str,
|
||||
_len: usize)
|
||||
-> Result<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeTupleVariant, Error> {
|
||||
Err(Error::unsupported_pair())
|
||||
}
|
||||
|
||||
fn serialize_map(self,
|
||||
_len: Option<usize>)
|
||||
-> Result<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeMap, Error> {
|
||||
Err(Error::unsupported_pair())
|
||||
}
|
||||
|
||||
fn serialize_struct(self,
|
||||
_name: &'static str,
|
||||
_len: usize)
|
||||
-> Result<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeStruct, Error> {
|
||||
Err(Error::unsupported_pair())
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(self,
|
||||
fn serialize_struct_variant
|
||||
(self,
|
||||
_name: &'static str,
|
||||
_variant_index: usize,
|
||||
_variant: &'static str,
|
||||
_len: usize)
|
||||
-> Result<VoidSerializer<()>, Error> {
|
||||
-> Result<Self::SerializeStructVariant, Error> {
|
||||
Err(Error::unsupported_pair())
|
||||
}
|
||||
}
|
||||
|
@ -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<S: Sink> ser::Serializer for PartSerializer<S> {
|
||||
type Ok = S::Ok;
|
||||
type Error = Error;
|
||||
type SerializeSeq = VoidSerializer<S::Ok>;
|
||||
type SerializeTuple = VoidSerializer<S::Ok>;
|
||||
type SerializeTupleStruct = VoidSerializer<S::Ok>;
|
||||
type SerializeTupleVariant = VoidSerializer<S::Ok>;
|
||||
type SerializeMap = VoidSerializer<S::Ok>;
|
||||
type SerializeStruct = VoidSerializer<S::Ok>;
|
||||
type SerializeStructVariant = VoidSerializer<S::Ok>;
|
||||
type SerializeSeq = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTuple = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTupleStruct = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTupleVariant = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeMap = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeStruct = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeStructVariant = ser::Impossible<S::Ok, Error>;
|
||||
|
||||
fn serialize_bool(self, v: bool) -> Result<S::Ok, Error> {
|
||||
self.sink.serialize_static_str(if v { "true" } else { "false" })
|
||||
@ -210,7 +209,7 @@ impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
||||
|
||||
impl<S: Sink> PartSerializer<S> {
|
||||
fn serialize_integer<I>(self, value: I) -> Result<S::Ok, Error>
|
||||
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<S: Sink> PartSerializer<S> {
|
||||
}
|
||||
|
||||
fn serialize_floating<F>(self, value: F) -> Result<S::Ok, Error>
|
||||
where F: dtoa::Floating
|
||||
where F: dtoa::Floating,
|
||||
{
|
||||
let mut buf = [b'\0'; 24];
|
||||
let len = dtoa::write(&mut buf[..], value).unwrap();
|
||||
|
122
src/ser/void.rs
122
src/ser/void.rs
@ -1,122 +0,0 @@
|
||||
use ser::Error;
|
||||
use serde::ser;
|
||||
use std::marker::PhantomData;
|
||||
use void;
|
||||
|
||||
pub struct VoidSerializer<Ok> {
|
||||
void: void::Void,
|
||||
_marker: PhantomData<Ok>,
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeSeq for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeTuple for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeTupleStruct for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeTupleVariant for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeMap for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_key<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_key: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn serialize_value<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeStruct for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_key: &'static str,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ok> ser::SerializeStructVariant for VoidSerializer<Ok> {
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
|
||||
_key: &'static str,
|
||||
_value: &T)
|
||||
-> Result<(), Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Ok, Error> {
|
||||
void::unreachable(self.void)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user