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]
|
[dependencies]
|
||||||
dtoa = "0.4.0"
|
dtoa = "0.4.0"
|
||||||
itoa = "0.3.0"
|
itoa = "0.3.0"
|
||||||
serde = "0.9.2"
|
serde = "0.9.3"
|
||||||
url = "1.0.0"
|
url = "1.0.0"
|
||||||
void = "1.0.2"
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
//! `x-www-form-urlencoded` meets Serde
|
//! `x-www-form-urlencoded` meets Serde
|
||||||
|
|
||||||
|
#![warn(unused_extern_crates)]
|
||||||
|
|
||||||
extern crate itoa;
|
extern crate itoa;
|
||||||
extern crate dtoa;
|
extern crate dtoa;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate void;
|
|
||||||
|
|
||||||
pub mod de;
|
pub mod de;
|
||||||
pub mod ser;
|
pub mod ser;
|
||||||
|
@ -4,7 +4,6 @@ mod key;
|
|||||||
mod pair;
|
mod pair;
|
||||||
mod part;
|
mod part;
|
||||||
mod value;
|
mod value;
|
||||||
mod void;
|
|
||||||
|
|
||||||
use serde::ser;
|
use serde::ser;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -102,21 +101,21 @@ pub struct SeqSerializer<'output, Target: 'output + UrlEncodedTarget> {
|
|||||||
///
|
///
|
||||||
/// Never instantiated, tuples are not supported at top-level.
|
/// Never instantiated, tuples are not supported at top-level.
|
||||||
pub struct TupleSerializer<'output, T: 'output + UrlEncodedTarget> {
|
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.
|
/// Tuple struct serializer.
|
||||||
///
|
///
|
||||||
/// Never instantiated, tuple structs are not supported.
|
/// Never instantiated, tuple structs are not supported.
|
||||||
pub struct TupleStructSerializer<'output, T: 'output + UrlEncodedTarget> {
|
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.
|
/// Tuple variant serializer.
|
||||||
///
|
///
|
||||||
/// Never instantiated, tuple variants are not supported.
|
/// Never instantiated, tuple variants are not supported.
|
||||||
pub struct TupleVariantSerializer<'output, T: 'output + UrlEncodedTarget> {
|
pub struct TupleVariantSerializer<'output, T: 'output + UrlEncodedTarget> {
|
||||||
inner: void::VoidSerializer<&'output mut UrlEncodedSerializer<T>>,
|
inner: ser::Impossible<&'output mut UrlEncodedSerializer<T>, Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Map serializer.
|
/// Map serializer.
|
||||||
@ -134,7 +133,7 @@ pub struct StructSerializer<'output, Target: 'output + UrlEncodedTarget> {
|
|||||||
///
|
///
|
||||||
/// Never instantiated, struct variants are not supported.
|
/// Never instantiated, struct variants are not supported.
|
||||||
pub struct StructVariantSerializer<'output, T: 'output + UrlEncodedTarget> {
|
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>
|
impl<'output, Target> ser::Serializer for Serializer<'output, Target>
|
||||||
|
@ -2,7 +2,6 @@ use ser::Error;
|
|||||||
use ser::key::KeySink;
|
use ser::key::KeySink;
|
||||||
use ser::part::PartSerializer;
|
use ser::part::PartSerializer;
|
||||||
use ser::value::ValueSink;
|
use ser::value::ValueSink;
|
||||||
use ser::void::VoidSerializer;
|
|
||||||
use serde::ser;
|
use serde::ser;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@ -30,13 +29,13 @@ impl<'target, Target> ser::Serializer for PairSerializer<'target, Target>
|
|||||||
{
|
{
|
||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type SerializeSeq = VoidSerializer<()>;
|
type SerializeSeq = ser::Impossible<(), Error>;
|
||||||
type SerializeTuple = Self;
|
type SerializeTuple = Self;
|
||||||
type SerializeTupleStruct = VoidSerializer<()>;
|
type SerializeTupleStruct = ser::Impossible<(), Error>;
|
||||||
type SerializeTupleVariant = VoidSerializer<()>;
|
type SerializeTupleVariant = ser::Impossible<(), Error>;
|
||||||
type SerializeMap = VoidSerializer<()>;
|
type SerializeMap = ser::Impossible<(), Error>;
|
||||||
type SerializeStruct = VoidSerializer<()>;
|
type SerializeStruct = ser::Impossible<(), Error>;
|
||||||
type SerializeStructVariant = VoidSerializer<()>;
|
type SerializeStructVariant = ser::Impossible<(), Error>;
|
||||||
|
|
||||||
fn serialize_bool(self, _v: bool) -> Result<(), Error> {
|
fn serialize_bool(self, _v: bool) -> Result<(), Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
@ -140,13 +139,13 @@ impl<'target, Target> ser::Serializer for PairSerializer<'target, Target>
|
|||||||
|
|
||||||
fn serialize_seq(self,
|
fn serialize_seq(self,
|
||||||
_len: Option<usize>)
|
_len: Option<usize>)
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
-> Result<Self::SerializeSeq, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_seq_fixed_size(self,
|
fn serialize_seq_fixed_size(self,
|
||||||
_len: usize)
|
_len: usize)
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
-> Result<Self::SerializeSeq, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,38 +160,40 @@ impl<'target, Target> ser::Serializer for PairSerializer<'target, Target>
|
|||||||
fn serialize_tuple_struct(self,
|
fn serialize_tuple_struct(self,
|
||||||
_name: &'static str,
|
_name: &'static str,
|
||||||
_len: usize)
|
_len: usize)
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
-> Result<Self::SerializeTupleStruct, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_tuple_variant(self,
|
fn serialize_tuple_variant
|
||||||
_name: &'static str,
|
(self,
|
||||||
_variant_index: usize,
|
_name: &'static str,
|
||||||
_variant: &'static str,
|
_variant_index: usize,
|
||||||
_len: usize)
|
_variant: &'static str,
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
_len: usize)
|
||||||
|
-> Result<Self::SerializeTupleVariant, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_map(self,
|
fn serialize_map(self,
|
||||||
_len: Option<usize>)
|
_len: Option<usize>)
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
-> Result<Self::SerializeMap, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_struct(self,
|
fn serialize_struct(self,
|
||||||
_name: &'static str,
|
_name: &'static str,
|
||||||
_len: usize)
|
_len: usize)
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
-> Result<Self::SerializeStruct, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_struct_variant(self,
|
fn serialize_struct_variant
|
||||||
_name: &'static str,
|
(self,
|
||||||
_variant_index: usize,
|
_name: &'static str,
|
||||||
_variant: &'static str,
|
_variant_index: usize,
|
||||||
_len: usize)
|
_variant: &'static str,
|
||||||
-> Result<VoidSerializer<()>, Error> {
|
_len: usize)
|
||||||
|
-> Result<Self::SerializeStructVariant, Error> {
|
||||||
Err(Error::unsupported_pair())
|
Err(Error::unsupported_pair())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use dtoa;
|
use dtoa;
|
||||||
use itoa;
|
use itoa;
|
||||||
use ser::Error;
|
use ser::Error;
|
||||||
use ser::void::VoidSerializer;
|
|
||||||
use serde::ser;
|
use serde::ser;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
@ -37,13 +36,13 @@ pub trait Sink: Sized {
|
|||||||
impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
||||||
type Ok = S::Ok;
|
type Ok = S::Ok;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type SerializeSeq = VoidSerializer<S::Ok>;
|
type SerializeSeq = ser::Impossible<S::Ok, Error>;
|
||||||
type SerializeTuple = VoidSerializer<S::Ok>;
|
type SerializeTuple = ser::Impossible<S::Ok, Error>;
|
||||||
type SerializeTupleStruct = VoidSerializer<S::Ok>;
|
type SerializeTupleStruct = ser::Impossible<S::Ok, Error>;
|
||||||
type SerializeTupleVariant = VoidSerializer<S::Ok>;
|
type SerializeTupleVariant = ser::Impossible<S::Ok, Error>;
|
||||||
type SerializeMap = VoidSerializer<S::Ok>;
|
type SerializeMap = ser::Impossible<S::Ok, Error>;
|
||||||
type SerializeStruct = VoidSerializer<S::Ok>;
|
type SerializeStruct = ser::Impossible<S::Ok, Error>;
|
||||||
type SerializeStructVariant = VoidSerializer<S::Ok>;
|
type SerializeStructVariant = ser::Impossible<S::Ok, Error>;
|
||||||
|
|
||||||
fn serialize_bool(self, v: bool) -> Result<S::Ok, Error> {
|
fn serialize_bool(self, v: bool) -> Result<S::Ok, Error> {
|
||||||
self.sink.serialize_static_str(if v { "true" } else { "false" })
|
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> {
|
impl<S: Sink> PartSerializer<S> {
|
||||||
fn serialize_integer<I>(self, value: I) -> Result<S::Ok, Error>
|
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 mut buf = [b'\0'; 20];
|
||||||
let len = itoa::write(&mut buf[..], value).unwrap();
|
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>
|
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 mut buf = [b'\0'; 24];
|
||||||
let len = dtoa::write(&mut buf[..], value).unwrap();
|
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