]>
git.proxmox.com Git - cargo.git/blob - vendor/serde-1.0.15/src/ser/impossible.rs
1 // Copyright 2017 Serde Developers
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 //! This module contains `Impossible` serializer and its implementations.
13 use ser
::{self, Serialize
, SerializeSeq
, SerializeTuple
, SerializeTupleStruct
,
14 SerializeTupleVariant
, SerializeMap
, SerializeStruct
, SerializeStructVariant
};
16 /// Helper type for implementing a `Serializer` that does not support
17 /// serializing one of the compound types.
19 /// This type cannot be instantiated, but implements every one of the traits
20 /// corresponding to the [`Serializer`] compound types: [`SerializeSeq`],
21 /// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
22 /// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
26 /// # extern crate serde;
28 /// # use serde::ser::{Serializer, Impossible};
29 /// # use serde::private::ser::Error;
31 /// # struct MySerializer;
33 /// impl Serializer for MySerializer {
35 /// type Error = Error;
37 /// type SerializeSeq = Impossible<(), Error>;
38 /// /* other associated types */
40 /// /// This data format does not support serializing sequences.
41 /// fn serialize_seq(self,
42 /// len: Option<usize>)
43 /// -> Result<Self::SerializeSeq, Error> {
44 /// // Given Impossible cannot be instantiated, the only
45 /// // thing we can do here is to return an error.
49 /// # unimplemented!()
52 /// /* other Serializer methods */
53 /// # __serialize_unimplemented! {
54 /// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str bytes none some
55 /// # unit unit_struct unit_variant newtype_struct newtype_variant
56 /// # tuple tuple_struct tuple_variant map struct struct_variant
63 /// [`Serializer`]: trait.Serializer.html
64 /// [`SerializeSeq`]: trait.SerializeSeq.html
65 /// [`SerializeTuple`]: trait.SerializeTuple.html
66 /// [`SerializeTupleStruct`]: trait.SerializeTupleStruct.html
67 /// [`SerializeTupleVariant`]: trait.SerializeTupleVariant.html
68 /// [`SerializeMap`]: trait.SerializeMap.html
69 /// [`SerializeStruct`]: trait.SerializeStruct.html
70 /// [`SerializeStructVariant`]: trait.SerializeStructVariant.html
71 pub struct Impossible
<Ok
, Error
> {
74 error
: PhantomData
<Error
>,
79 impl<Ok
, Error
> SerializeSeq
for Impossible
<Ok
, Error
>
86 fn serialize_element
<T
: ?Sized
>(&mut self, value
: &T
) -> Result
<(), Error
>
94 fn end(self) -> Result
<Ok
, Error
> {
99 impl<Ok
, Error
> SerializeTuple
for Impossible
<Ok
, Error
>
106 fn serialize_element
<T
: ?Sized
>(&mut self, value
: &T
) -> Result
<(), Error
>
114 fn end(self) -> Result
<Ok
, Error
> {
119 impl<Ok
, Error
> SerializeTupleStruct
for Impossible
<Ok
, Error
>
126 fn serialize_field
<T
: ?Sized
>(&mut self, value
: &T
) -> Result
<(), Error
>
134 fn end(self) -> Result
<Ok
, Error
> {
139 impl<Ok
, Error
> SerializeTupleVariant
for Impossible
<Ok
, Error
>
146 fn serialize_field
<T
: ?Sized
>(&mut self, value
: &T
) -> Result
<(), Error
>
154 fn end(self) -> Result
<Ok
, Error
> {
159 impl<Ok
, Error
> SerializeMap
for Impossible
<Ok
, Error
>
166 fn serialize_key
<T
: ?Sized
>(&mut self, key
: &T
) -> Result
<(), Error
>
174 fn serialize_value
<T
: ?Sized
>(&mut self, value
: &T
) -> Result
<(), Error
>
182 fn end(self) -> Result
<Ok
, Error
> {
187 impl<Ok
, Error
> SerializeStruct
for Impossible
<Ok
, Error
>
194 fn serialize_field
<T
: ?Sized
>(&mut self, key
: &'
static str, value
: &T
) -> Result
<(), Error
>
203 fn end(self) -> Result
<Ok
, Error
> {
208 impl<Ok
, Error
> SerializeStructVariant
for Impossible
<Ok
, Error
>
215 fn serialize_field
<T
: ?Sized
>(&mut self, key
: &'
static str, value
: &T
) -> Result
<(), Error
>
224 fn end(self) -> Result
<Ok
, Error
> {