aboutsummaryrefslogtreecommitdiff
path: root/src/ser.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-12-17 17:45:35 -0800
committerAlex Crichton <alex@alexcrichton.com>2018-12-17 17:45:35 -0800
commitc1a369f44762045e65989caa9491e153d1f358e6 (patch)
tree5fef35e1bd647687cdecda830134d5079d64ea4d /src/ser.rs
parent1ef180d06ed4ec207c41b2595feaca84959e709e (diff)
downloadmilf-rs-c1a369f44762045e65989caa9491e153d1f358e6.tar.gz
milf-rs-c1a369f44762045e65989caa9491e153d1f358e6.zip
Run `cargo fmt`
Diffstat (limited to 'src/ser.rs')
-rw-r--r--src/ser.rs560
1 files changed, 316 insertions, 244 deletions
diff --git a/src/ser.rs b/src/ser.rs
index e1fe1a2..60e5b50 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -32,8 +32,8 @@ use std::fmt::{self, Write};
use std::marker;
use std::rc::Rc;
-use serde::ser;
use datetime;
+use serde::ser;
/// Serialize the given data structure as a TOML byte vector.
///
@@ -41,7 +41,8 @@ use datetime;
/// fail, if `T` contains a map with non-string keys, or if `T` attempts to
/// serialize an unsupported datatype such as an enum, tuple, or tuple struct.
pub fn to_vec<T: ?Sized>(value: &T) -> Result<Vec<u8>, Error>
- where T: ser::Serialize,
+where
+ T: ser::Serialize,
{
to_string(value).map(|e| e.into_bytes())
}
@@ -87,7 +88,8 @@ pub fn to_vec<T: ?Sized>(value: &T) -> Result<Vec<u8>, Error>
/// }
/// ```
pub fn to_string<T: ?Sized>(value: &T) -> Result<String, Error>
- where T: ser::Serialize,
+where
+ T: ser::Serialize,
{
let mut dst = String::with_capacity(128);
value.serialize(&mut Serializer::new(&mut dst))?;
@@ -99,7 +101,8 @@ pub fn to_string<T: ?Sized>(value: &T) -> Result<String, Error>
/// This is identical to `to_string` except the output string has a more
/// "pretty" output. See `Serializer::pretty` for more details.
pub fn to_string_pretty<T: ?Sized>(value: &T) -> Result<String, Error>
- where T: ser::Serialize,
+where
+ T: ser::Serialize,
{
let mut dst = String::with_capacity(128);
value.serialize(&mut Serializer::pretty(&mut dst))?;
@@ -177,9 +180,7 @@ struct StringSettings {
impl StringSettings {
fn pretty() -> StringSettings {
- StringSettings {
- literal: true,
- }
+ StringSettings { literal: true }
}
}
@@ -239,7 +240,7 @@ pub enum SerializeTable<'a: 'b, 'b> {
key: String,
first: Cell<bool>,
table_emitted: Cell<bool>,
- }
+ },
}
impl<'a> Serializer<'a> {
@@ -333,13 +334,13 @@ impl<'a> Serializer<'a> {
/// """
/// ```
pub fn pretty_string_literal(&mut self, value: bool) -> &mut Self {
- let use_default = if let &mut Some(ref mut s) = &mut Rc::get_mut(&mut self.settings)
- .unwrap().string {
- s.literal = value;
- false
- } else {
- true
- };
+ let use_default =
+ if let &mut Some(ref mut s) = &mut Rc::get_mut(&mut self.settings).unwrap().string {
+ s.literal = value;
+ false
+ } else {
+ true
+ };
if use_default {
let mut string = StringSettings::pretty();
@@ -389,13 +390,13 @@ impl<'a> Serializer<'a> {
///
/// See `Serializer::pretty_array` for more details.
pub fn pretty_array_indent(&mut self, value: usize) -> &mut Self {
- let use_default = if let &mut Some(ref mut a) = &mut Rc::get_mut(&mut self.settings)
- .unwrap().array {
- a.indent = value;
- false
- } else {
- true
- };
+ let use_default =
+ if let &mut Some(ref mut a) = &mut Rc::get_mut(&mut self.settings).unwrap().array {
+ a.indent = value;
+ false
+ } else {
+ true
+ };
if use_default {
let mut array = ArraySettings::pretty();
@@ -409,13 +410,13 @@ impl<'a> Serializer<'a> {
///
/// See `Serializer::pretty_array` for more details.
pub fn pretty_array_trailing_comma(&mut self, value: bool) -> &mut Self {
- let use_default = if let &mut Some(ref mut a) = &mut Rc::get_mut(&mut self.settings)
- .unwrap().array {
- a.trailing_comma = value;
- false
- } else {
- true
- };
+ let use_default =
+ if let &mut Some(ref mut a) = &mut Rc::get_mut(&mut self.settings).unwrap().array {
+ a.trailing_comma = value;
+ false
+ } else {
+ true
+ };
if use_default {
let mut array = ArraySettings::pretty();
@@ -425,9 +426,7 @@ impl<'a> Serializer<'a> {
self
}
- fn display<T: fmt::Display>(&mut self,
- t: T,
- type_: &'static str) -> Result<(), Error> {
+ fn display<T: fmt::Display>(&mut self, t: T, type_: &'static str) -> Result<(), Error> {
self.emit_key(type_)?;
drop(write!(self.dst, "{}", t));
if let State::Table { .. } = self.state {
@@ -446,16 +445,26 @@ impl<'a> Serializer<'a> {
fn _emit_key(&mut self, state: &State) -> Result<(), Error> {
match *state {
State::End => Ok(()),
- State::Array { parent, first, type_, len } => {
+ State::Array {
+ parent,
+ first,
+ type_,
+ len,
+ } => {
assert!(type_.get().is_some());
if first.get() {
self._emit_key(parent)?;
}
self.emit_array(first, len)
}
- State::Table { parent, first, table_emitted, key } => {
+ State::Table {
+ parent,
+ first,
+ table_emitted,
+ key,
+ } => {
if table_emitted.get() {
- return Err(Error::ValueAfterTable)
+ return Err(Error::ValueAfterTable);
}
if first.get() {
self.emit_table_header(parent)?;
@@ -476,7 +485,7 @@ impl<'a> Serializer<'a> {
} else {
self.dst.push_str(", ")
}
- },
+ }
(_, &Some(ref a)) => {
if first.get() {
self.dst.push_str("[\n")
@@ -486,7 +495,7 @@ impl<'a> Serializer<'a> {
for _ in 0..a.indent {
self.dst.push_str(" ");
}
- },
+ }
}
Ok(())
}
@@ -498,7 +507,7 @@ impl<'a> Serializer<'a> {
};
if let Some(prev) = prev.get() {
if prev != type_ {
- return Err(Error::ArrayMixedType)
+ return Err(Error::ArrayMixedType);
}
} else {
prev.set(Some(type_));
@@ -507,14 +516,9 @@ impl<'a> Serializer<'a> {
}
fn escape_key(&mut self, key: &str) -> Result<(), Error> {
- let ok = key.chars().all(|c| {
- match c {
- 'a' ... 'z' |
- 'A' ... 'Z' |
- '0' ... '9' |
- '-' | '_' => true,
- _ => false,
- }
+ let ok = key.chars().all(|c| match c {
+ 'a'...'z' | 'A'...'Z' | '0'...'9' | '-' | '_' => true,
+ _ => false,
});
if ok {
drop(write!(self.dst, "{}", key));
@@ -570,7 +574,7 @@ impl<'a> Serializer<'a> {
found_singles = 0
}
match ch {
- '\t' => {},
+ '\t' => {}
'\n' => ty = Type::NewlineTripple,
// note that the following are invalid: \b \f \r
c if c < '\u{1f}' => can_be_pretty = false, // Invalid control character
@@ -606,8 +610,9 @@ impl<'a> Serializer<'a> {
let repr = if !is_key && self.settings.string.is_some() {
match (&self.settings.string, do_pretty(value)) {
- (&Some(StringSettings { literal: false, .. }), Repr::Literal(_, ty)) =>
- Repr::Std(ty),
+ (&Some(StringSettings { literal: false, .. }), Repr::Literal(_, ty)) => {
+ Repr::Std(ty)
+ }
(_, r @ _) => r,
}
} else {
@@ -626,26 +631,23 @@ impl<'a> Serializer<'a> {
Type::OnelineSingle => self.dst.push('\''),
_ => self.dst.push_str("'''"),
}
- },
+ }
Repr::Std(ty) => {
match ty {
- Type::NewlineTripple => self.dst.push_str("\"\"\"\n"),
+ Type::NewlineTripple => self.dst.push_str("\"\"\"\n"),
// note: OnelineTripple can happen if do_pretty wants to do
// '''it's one line'''
// but settings.string.literal == false
- Type::OnelineSingle |
- Type::OnelineTripple => self.dst.push('"'),
+ Type::OnelineSingle | Type::OnelineTripple => self.dst.push('"'),
}
for ch in value.chars() {
match ch {
'\u{8}' => self.dst.push_str("\\b"),
'\u{9}' => self.dst.push_str("\\t"),
- '\u{a}' => {
- match ty {
- Type::NewlineTripple => self.dst.push('\n'),
- Type::OnelineSingle => self.dst.push_str("\\n"),
- _ => unreachable!(),
- }
+ '\u{a}' => match ty {
+ Type::NewlineTripple => self.dst.push('\n'),
+ Type::OnelineSingle => self.dst.push_str("\\n"),
+ _ => unreachable!(),
},
'\u{c}' => self.dst.push_str("\\f"),
'\u{d}' => self.dst.push_str("\\r"),
@@ -656,10 +658,10 @@ impl<'a> Serializer<'a> {
}
}
match ty {
- Type::NewlineTripple => self.dst.push_str("\"\"\""),
+ Type::NewlineTripple => self.dst.push_str("\"\"\""),
Type::OnelineSingle | Type::OnelineTripple => self.dst.push('"'),
}
- },
+ }
}
Ok(())
}
@@ -684,7 +686,11 @@ impl<'a> Serializer<'a> {
if !first.get() {
break;
}
- if let State::Array { parent: &State::Table {..}, ..} = *parent {
+ if let State::Array {
+ parent: &State::Table { .. },
+ ..
+ } = *parent
+ {
self.emit_table_header(parent)?;
break;
}
@@ -697,7 +703,7 @@ impl<'a> Serializer<'a> {
// table in the document.
self.dst.push('\n');
}
- },
+ }
State::Array { parent, first, .. } => {
if !first.get() {
// Always newline if we are not the first item in the
@@ -709,7 +715,7 @@ impl<'a> Serializer<'a> {
self.dst.push('\n');
}
}
- },
+ }
_ => {}
}
self.dst.push_str("[");
@@ -728,9 +734,14 @@ impl<'a> Serializer<'a> {
match *key {
State::Array { parent, .. } => self.emit_key_part(parent),
State::End => Ok(true),
- State::Table { key, parent, table_emitted, .. } => {
+ State::Table {
+ key,
+ parent,
+ table_emitted,
+ ..
+ } => {
table_emitted.set(true);
- let first = self.emit_key_part(parent)?;
+ let first = self.emit_key_part(parent)?;
if !first {
self.dst.push_str(".");
}
@@ -841,7 +852,8 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> {
}
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<(), Self::Error>
- where T: ser::Serialize
+ where
+ T: ser::Serialize,
{
value.serialize(self)
}
@@ -850,40 +862,44 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> {
Err(Error::UnsupportedType)
}
- fn serialize_unit_struct(self,
- _name: &'static str)
- -> Result<(), Self::Error> {
+ fn serialize_unit_struct(self, _name: &'static str) -> Result<(), Self::Error> {
Err(Error::UnsupportedType)
}
- fn serialize_unit_variant(self,
- _name: &'static str,
- _variant_index: u32,
- variant: &'static str)
- -> Result<(), Self::Error> {
+ fn serialize_unit_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ variant: &'static str,
+ ) -> Result<(), Self::Error> {
self.serialize_str(variant)
}
- fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T)
- -> Result<(), Self::Error>
- where T: ser::Serialize,
+ fn serialize_newtype_struct<T: ?Sized>(
+ self,
+ _name: &'static str,
+ value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: ser::Serialize,
{
value.serialize(self)
}
- fn serialize_newtype_variant<T: ?Sized>(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _value: &T)
- -> Result<(), Self::Error>
- where T: ser::Serialize,
+ fn serialize_newtype_variant<T: ?Sized>(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: ser::Serialize,
{
Err(Error::UnsupportedType)
}
- fn serialize_seq(self, len: Option<usize>)
- -> Result<Self::SerializeSeq, Self::Error> {
+ fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
self.array_type("array")?;
Ok(SerializeSeq {
ser: self,
@@ -893,27 +909,29 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> {
})
}
- fn serialize_tuple(self, len: usize)
- -> Result<Self::SerializeTuple, Self::Error> {
+ fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
self.serialize_seq(Some(len))
}
- fn serialize_tuple_struct(self, _name: &'static str, len: usize)
- -> Result<Self::SerializeTupleStruct, Self::Error> {
+ fn serialize_tuple_struct(
+ self,
+ _name: &'static str,
+ len: usize,
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> {
self.serialize_seq(Some(len))
}
- fn serialize_tuple_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- len: usize)
- -> Result<Self::SerializeTupleVariant, Self::Error> {
+ fn serialize_tuple_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ len: usize,
+ ) -> Result<Self::SerializeTupleVariant, Self::Error> {
self.serialize_seq(Some(len))
}
- fn serialize_map(self, _len: Option<usize>)
- -> Result<Self::SerializeMap, Self::Error> {
+ fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
self.array_type("table")?;
Ok(SerializeTable::Table {
ser: self,
@@ -923,8 +941,11 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> {
})
}
- fn serialize_struct(self, name: &'static str, _len: usize)
- -> Result<Self::SerializeStruct, Self::Error> {
+ fn serialize_struct(
+ self,
+ name: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStruct, Self::Error> {
if name == datetime::NAME {
self.array_type("datetime")?;
Ok(SerializeTable::Datetime(self))
@@ -939,12 +960,13 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> {
}
}
- fn serialize_struct_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _len: usize)
- -> Result<Self::SerializeStructVariant, Self::Error> {
+ fn serialize_struct_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
Err(Error::UnsupportedType)
}
}
@@ -954,7 +976,8 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
- where T: ser::Serialize,
+ where
+ T: ser::Serialize,
{
value.serialize(&mut Serializer {
dst: &mut *self.ser.dst,
@@ -973,19 +996,17 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
fn end(self) -> Result<(), Error> {
match self.type_.get() {
Some("table") => return Ok(()),
- Some(_) => {
- match (self.len, &self.ser.settings.array) {
- (Some(0...1), _) | (_, &None) => {
- self.ser.dst.push_str("]");
- },
- (_, &Some(ref a)) => {
- if a.trailing_comma {
- self.ser.dst.push_str(",");
- }
- self.ser.dst.push_str("\n]");
- },
+ Some(_) => match (self.len, &self.ser.settings.array) {
+ (Some(0...1), _) | (_, &None) => {
+ self.ser.dst.push_str("]");
}
- }
+ (_, &Some(ref a)) => {
+ if a.trailing_comma {
+ self.ser.dst.push_str(",");
+ }
+ self.ser.dst.push_str("\n]");
+ }
+ },
None => {
assert!(self.first.get());
self.ser.emit_key("array")?;
@@ -1004,7 +1025,8 @@ impl<'a, 'b> ser::SerializeTuple for SerializeSeq<'a, 'b> {
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
- where T: ser::Serialize,
+ where
+ T: ser::Serialize,
{
ser::SerializeSeq::serialize_element(self, value)
}
@@ -1019,7 +1041,8 @@ impl<'a, 'b> ser::SerializeTupleVariant for SerializeSeq<'a, 'b> {
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
- where T: ser::Serialize,
+ where
+ T: ser::Serialize,
{
ser::SerializeSeq::serialize_element(self, value)
}
@@ -1034,7 +1057,8 @@ impl<'a, 'b> ser::SerializeTupleStruct for SerializeSeq<'a, 'b> {
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
- where T: ser::Serialize,
+ where
+ T: ser::Serialize,
{
ser::SerializeSeq::serialize_element(self, value)
}
@@ -1049,7 +1073,8 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> {
type Error = Error;
fn serialize_key<T: ?Sized>(&mut self, input: &T) -> Result<(), Error>
- where T: ser::Serialize,
+ where
+ T: ser::Serialize,
{
match *self {
SerializeTable::Datetime(_) => panic!(), // shouldn't be possible
@@ -1062,7 +1087,8 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> {
}
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
- where T: ser::Serialize,
+ where
+ T: ser::Serialize,
{
match *self {
SerializeTable::Datetime(_) => panic!(), // shouldn't be possible
@@ -1085,7 +1111,7 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> {
});
match res {
Ok(()) => first.set(false),
- Err(Error::UnsupportedNone) => {},
+ Err(Error::UnsupportedNone) => {}
Err(e) => return Err(e),
}
}
@@ -1096,7 +1122,7 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> {
fn end(self) -> Result<(), Error> {
match self {
SerializeTable::Datetime(_) => panic!(), // shouldn't be possible
- SerializeTable::Table { ser, first, .. } => {
+ SerializeTable::Table { ser, first, .. } => {
if first.get() {
let state = ser.state.clone();
ser.emit_table_header(&state)?;
@@ -1111,16 +1137,16 @@ impl<'a, 'b> ser::SerializeStruct for SerializeTable<'a, 'b> {
type Ok = ();
type Error = Error;
- fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T)
- -> Result<(), Error>
- where T: ser::Serialize,
+ fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
+ where
+ T: ser::Serialize,
{
match *self {
SerializeTable::Datetime(ref mut ser) => {
if key == datetime::FIELD {
value.serialize(DateStrEmitter(&mut *ser))?;
} else {
- return Err(Error::DateInvalid)
+ return Err(Error::DateInvalid);
}
}
SerializeTable::Table {
@@ -1141,7 +1167,7 @@ impl<'a, 'b> ser::SerializeStruct for SerializeTable<'a, 'b> {
});
match res {
Ok(()) => first.set(false),
- Err(Error::UnsupportedNone) => {},
+ Err(Error::UnsupportedNone) => {}
Err(e) => return Err(e),
}
}
@@ -1151,8 +1177,8 @@ impl<'a, 'b> ser::SerializeStruct for SerializeTable<'a, 'b> {
fn end(self) -> Result<(), Error> {
match self {
- SerializeTable::Datetime(_) => {},
- SerializeTable::Table { ser, first, .. } => {
+ SerializeTable::Datetime(_) => {}
+ SerializeTable::Table { ser, first, .. } => {
if first.get() {
let state = ser.state.clone();
ser.emit_table_header(&state)?;
@@ -1238,7 +1264,8 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> {
}
fn serialize_some<T: ?Sized>(self, _value: &T) -> Result<(), Self::Error>
- where T: ser::Serialize
+ where
+ T: ser::Serialize,
{
Err(Error::KeyNotString)
}
@@ -1247,78 +1274,88 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> {
Err(Error::KeyNotString)
}
- fn serialize_unit_struct(self,
- _name: &'static str)
- -> Result<(), Self::Error> {
+ fn serialize_unit_struct(self, _name: &'static str) -> Result<(), Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_unit_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str)
- -> Result<(), Self::Error> {
+ fn serialize_unit_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ ) -> Result<(), Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, _value: &T)
- -> Result<(), Self::Error>
- where T: ser::Serialize,
+ fn serialize_newtype_struct<T: ?Sized>(
+ self,
+ _name: &'static str,
+ _value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: ser::Serialize,
{
Err(Error::DateInvalid)
}
- fn serialize_newtype_variant<T: ?Sized>(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _value: &T)
- -> Result<(), Self::Error>
- where T: ser::Serialize,
+ fn serialize_newtype_variant<T: ?Sized>(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: ser::Serialize,
{
Err(Error::DateInvalid)
}
- fn serialize_seq(self, _len: Option<usize>)
- -> Result<Self::SerializeSeq, Self::Error> {
+ fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_tuple(self, _len: usize)
- -> Result<Self::SerializeTuple, Self::Error> {
+ fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_tuple_struct(self, _name: &'static str, _len: usize)
- -> Result<Self::SerializeTupleStruct, Self::Error> {
+ fn serialize_tuple_struct(
+ self,
+ _name: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_tuple_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _len: usize)
- -> Result<Self::SerializeTupleVariant, Self::Error> {
+ fn serialize_tuple_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeTupleVariant, Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_map(self, _len: Option<usize>)
- -> Result<Self::SerializeMap, Self::Error> {
+ fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_struct(self, _name: &'static str, _len: usize)
- -> Result<Self::SerializeStruct, Self::Error> {
+ fn serialize_struct(
+ self,
+ _name: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStruct, Self::Error> {
Err(Error::DateInvalid)
}
- fn serialize_struct_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _len: usize)
- -> Result<Self::SerializeStructVariant, Self::Error> {
+ fn serialize_struct_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
Err(Error::DateInvalid)
}
}
@@ -1397,7 +1434,8 @@ impl ser::Serializer for StringExtractor {
}
fn serialize_some<T: ?Sized>(self, _value: &T) -> Result<String, Self::Error>
- where T: ser::Serialize
+ where
+ T: ser::Serialize,
{
Err(Error::KeyNotString)
}
@@ -1406,78 +1444,88 @@ impl ser::Serializer for StringExtractor {
Err(Error::KeyNotString)
}
- fn serialize_unit_struct(self,
- _name: &'static str)
- -> Result<String, Self::Error> {
+ fn serialize_unit_struct(self, _name: &'static str) -> Result<String, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_unit_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str)
- -> Result<String, Self::Error> {
+ fn serialize_unit_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ ) -> Result<String, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T)
- -> Result<String, Self::Error>
- where T: ser::Serialize,
+ fn serialize_newtype_struct<T: ?Sized>(
+ self,
+ _name: &'static str,
+ value: &T,
+ ) -> Result<String, Self::Error>
+ where
+ T: ser::Serialize,
{
value.serialize(self)
}
- fn serialize_newtype_variant<T: ?Sized>(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _value: &T)
- -> Result<String, Self::Error>
- where T: ser::Serialize,
+ fn serialize_newtype_variant<T: ?Sized>(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _value: &T,
+ ) -> Result<String, Self::Error>
+ where
+ T: ser::Serialize,
{
Err(Error::KeyNotString)
}
- fn serialize_seq(self, _len: Option<usize>)
- -> Result<Self::SerializeSeq, Self::Error> {
+ fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_tuple(self, _len: usize)
- -> Result<Self::SerializeTuple, Self::Error> {
+ fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_tuple_struct(self, _name: &'static str, _len: usize)
- -> Result<Self::SerializeTupleStruct, Self::Error> {
+ fn serialize_tuple_struct(
+ self,
+ _name: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_tuple_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _len: usize)
- -> Result<Self::SerializeTupleVariant, Self::Error> {
+ fn serialize_tuple_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeTupleVariant, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_map(self, _len: Option<usize>)
- -> Result<Self::SerializeMap, Self::Error> {
+ fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_struct(self, _name: &'static str, _len: usize)
- -> Result<Self::SerializeStruct, Self::Error> {
+ fn serialize_struct(
+ self,
+ _name: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStruct, Self::Error> {
Err(Error::KeyNotString)
}
- fn serialize_struct_variant(self,
- _name: &'static str,
- _variant_index: u32,
- _variant: &'static str,
- _len: usize)
- -> Result<Self::SerializeStructVariant, Self::Error> {
+ fn serialize_struct_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
Err(Error::KeyNotString)
}
}
@@ -1549,12 +1597,12 @@ enum Category {
/// # type Dependency = String;
/// # fn main() {}
/// ```
-pub fn tables_last<'a, I, K, V, S>(data: &'a I, serializer: S)
- -> Result<S::Ok, S::Error>
- where &'a I: IntoIterator<Item = (K, V)>,
- K: ser::Serialize,
- V: ser::Serialize,
- S: ser::Serializer
+pub fn tables_last<'a, I, K, V, S>(data: &'a I, serializer: S) -> Result<S::Ok, S::Error>
+where
+ &'a I: IntoIterator<Item = (K, V)>,
+ K: ser::Serialize,
+ V: ser::Serialize,
+ S: ser::Serializer,
{
use serde::ser::SerializeMap;
@@ -1668,15 +1716,30 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> {
Err(ser::Error::custom("unsupported"))
}
- fn serialize_unit_variant(self, _: &'static str, _: u32, _: &'static str) -> Result<Self::Ok, Self::Error> {
+ fn serialize_unit_variant(
+ self,
+ _: &'static str,
+ _: u32,
+ _: &'static str,
+ ) -> Result<Self::Ok, Self::Error> {
Err(ser::Error::custom("unsupported"))
}
- fn serialize_newtype_struct<T: ?Sized + ser::Serialize>(self, _: &'static str, v: &T) -> Result<Self::Ok, Self::Error> {
+ fn serialize_newtype_struct<T: ?Sized + ser::Serialize>(
+ self,
+ _: &'static str,
+ v: &T,
+ ) -> Result<Self::Ok, Self::Error> {
v.serialize(self)
}
- fn serialize_newtype_variant<T: ?Sized + ser::Serialize>(self, _: &'static str, _: u32, _: &'static str, _: &T) -> Result<Self::Ok, Self::Error> {
+ fn serialize_newtype_variant<T: ?Sized + ser::Serialize>(
+ self,
+ _: &'static str,
+ _: u32,
+ _: &'static str,
+ _: &T,
+ ) -> Result<Self::Ok, Self::Error> {
Err(ser::Error::custom("unsupported"))
}
@@ -1688,11 +1751,21 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> {
Ok(self)
}
- fn serialize_tuple_struct(self, _: &'static str, _: usize) -> Result<Self::SerializeTupleStruct, Self::Error> {
+ fn serialize_tuple_struct(
+ self,
+ _: &'static str,
+ _: usize,
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> {
Ok(self)
}
- fn serialize_tuple_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Result<Self::SerializeTupleVariant, Self::Error> {
+ fn serialize_tuple_variant(
+ self,
+ _: &'static str,
+ _: u32,
+ _: &'static str,
+ _: usize,
+ ) -> Result<Self::SerializeTupleVariant, Self::Error> {
Ok(self)
}
@@ -1704,7 +1777,13 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> {
Ok(self)
}
- fn serialize_struct_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Result<Self::SerializeStructVariant, Self::Error> {
+ fn serialize_struct_variant(
+ self,
+ _: &'static str,
+ _: u32,
+ _: &'static str,
+ _: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
Err(ser::Error::custom("unsupported"))
}
}
@@ -1713,8 +1792,7 @@ impl<E: ser::Error> ser::SerializeSeq for Categorize<E> {
type Ok = Category;
type Error = E;
- fn serialize_element<T: ?Sized + ser::Serialize>(&mut self, _: &T)
- -> Result<(), Self::Error> {
+ fn serialize_element<T: ?Sized + ser::Serialize>(&mut self, _: &T) -> Result<(), Self::Error> {
Ok(())
}
@@ -1727,8 +1805,7 @@ impl<E: ser::Error> ser::SerializeTuple for Categorize<E> {
type Ok = Category;
type Error = E;
- fn serialize_element<T: ?Sized + ser::Serialize>(&mut self, _: &T)
- -> Result<(), Self::Error> {
+ fn serialize_element<T: ?Sized + ser::Serialize>(&mut self, _: &T) -> Result<(), Self::Error> {
Ok(())
}
@@ -1741,8 +1818,7 @@ impl<E: ser::Error> ser::SerializeTupleVariant for Categorize<E> {
type Ok = Category;
type Error = E;
- fn serialize_field<T: ?Sized + ser::Serialize>(&mut self, _: &T)
- -> Result<(), Self::Error> {
+ fn serialize_field<T: ?Sized + ser::Serialize>(&mut self, _: &T) -> Result<(), Self::Error> {
Ok(())
}
@@ -1755,8 +1831,7 @@ impl<E: ser::Error> ser::SerializeTupleStruct for Categorize<E> {
type Ok = Category;
type Error = E;
- fn serialize_field<T: ?Sized + ser::Serialize>(&mut self, _: &T)
- -> Result<(), Self::Error> {
+ fn serialize_field<T: ?Sized + ser::Serialize>(&mut self, _: &T) -> Result<(), Self::Error> {
Ok(())
}
@@ -1769,13 +1844,11 @@ impl<E: ser::Error> ser::SerializeMap for Categorize<E> {
type Ok = Category;
type Error = E;
- fn serialize_key<T: ?Sized + ser::Serialize>(&mut self, _: &T)
- -> Result<(), Self::Error> {
+ fn serialize_key<T: ?Sized + ser::Serialize>(&mut self, _: &T) -> Result<(), Self::Error> {
Ok(())
}
- fn serialize_value<T: ?Sized + ser::Serialize>(&mut self, _: &T)
- -> Result<(), Self::Error> {
+ fn serialize_value<T: ?Sized + ser::Serialize>(&mut self, _: &T) -> Result<(), Self::Error> {
Ok(())
}
@@ -1788,10 +1861,9 @@ impl<E: ser::Error> ser::SerializeStruct for Categorize<E> {
type Ok = Category;
type Error = E;
- fn serialize_field<T: ?Sized>(&mut self,
- _: &'static str,
- _: &T) -> Result<(), Self::Error>
- where T: ser::Serialize,
+ fn serialize_field<T: ?Sized>(&mut self, _: &'static str, _: &T) -> Result<(), Self::Error>
+ where
+ T: ser::Serialize,
{
Ok(())
}