summaryrefslogtreecommitdiffstats
path: root/vendor/toml_edit-0.19.11/src/ser
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/toml_edit-0.19.11/src/ser')
-rw-r--r--vendor/toml_edit-0.19.11/src/ser/array.rs84
-rw-r--r--vendor/toml_edit-0.19.11/src/ser/key.rs173
-rw-r--r--vendor/toml_edit-0.19.11/src/ser/map.rs405
-rw-r--r--vendor/toml_edit-0.19.11/src/ser/mod.rs165
-rw-r--r--vendor/toml_edit-0.19.11/src/ser/pretty.rs45
-rw-r--r--vendor/toml_edit-0.19.11/src/ser/value.rs243
6 files changed, 1115 insertions, 0 deletions
diff --git a/vendor/toml_edit-0.19.11/src/ser/array.rs b/vendor/toml_edit-0.19.11/src/ser/array.rs
new file mode 100644
index 000000000..80eba8ba7
--- /dev/null
+++ b/vendor/toml_edit-0.19.11/src/ser/array.rs
@@ -0,0 +1,84 @@
+use super::Error;
+
+#[doc(hidden)]
+pub struct SerializeValueArray {
+ values: Vec<crate::Item>,
+}
+
+impl SerializeValueArray {
+ pub(crate) fn new() -> Self {
+ Self { values: Vec::new() }
+ }
+
+ pub(crate) fn with_capacity(len: usize) -> Self {
+ Self {
+ values: Vec::with_capacity(len),
+ }
+ }
+}
+
+impl serde::ser::SerializeSeq for SerializeValueArray {
+ type Ok = crate::Value;
+ type Error = Error;
+
+ fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ let value = value.serialize(super::ValueSerializer {})?;
+ self.values.push(crate::Item::Value(value));
+ Ok(())
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ Ok(crate::Value::Array(crate::Array::with_vec(self.values)))
+ }
+}
+
+impl serde::ser::SerializeTuple for SerializeValueArray {
+ type Ok = crate::Value;
+ type Error = Error;
+
+ fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ serde::ser::SerializeSeq::serialize_element(self, value)
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ serde::ser::SerializeSeq::end(self)
+ }
+}
+
+impl serde::ser::SerializeTupleVariant for SerializeValueArray {
+ type Ok = crate::Value;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ serde::ser::SerializeSeq::serialize_element(self, value)
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ serde::ser::SerializeSeq::end(self)
+ }
+}
+
+impl serde::ser::SerializeTupleStruct for SerializeValueArray {
+ type Ok = crate::Value;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ serde::ser::SerializeSeq::serialize_element(self, value)
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ serde::ser::SerializeSeq::end(self)
+ }
+}
diff --git a/vendor/toml_edit-0.19.11/src/ser/key.rs b/vendor/toml_edit-0.19.11/src/ser/key.rs
new file mode 100644
index 000000000..d5e381bf7
--- /dev/null
+++ b/vendor/toml_edit-0.19.11/src/ser/key.rs
@@ -0,0 +1,173 @@
+use crate::InternalString;
+
+use super::Error;
+
+pub(crate) struct KeySerializer;
+
+impl serde::ser::Serializer for KeySerializer {
+ type Ok = InternalString;
+ type Error = Error;
+ type SerializeSeq = serde::ser::Impossible<InternalString, Error>;
+ type SerializeTuple = serde::ser::Impossible<InternalString, Error>;
+ type SerializeTupleStruct = serde::ser::Impossible<InternalString, Error>;
+ type SerializeTupleVariant = serde::ser::Impossible<InternalString, Error>;
+ type SerializeMap = serde::ser::Impossible<InternalString, Error>;
+ type SerializeStruct = serde::ser::Impossible<InternalString, Error>;
+ type SerializeStructVariant = serde::ser::Impossible<InternalString, Error>;
+
+ fn serialize_bool(self, _v: bool) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_i8(self, _v: i8) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_i16(self, _v: i16) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_i32(self, _v: i32) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_i64(self, _v: i64) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_u8(self, _v: u8) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_u16(self, _v: u16) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_u32(self, _v: u32) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_u64(self, _v: u64) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_f32(self, _v: f32) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_f64(self, _v: f64) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_char(self, _v: char) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_str(self, value: &str) -> Result<InternalString, Self::Error> {
+ Ok(InternalString::from(value))
+ }
+
+ fn serialize_bytes(self, _value: &[u8]) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_none(self) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_some<T: ?Sized>(self, _value: &T) -> Result<InternalString, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_unit(self) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_unit_struct(self, _name: &'static str) -> Result<InternalString, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_unit_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ variant: &'static str,
+ ) -> Result<InternalString, Self::Error> {
+ Ok(variant.into())
+ }
+
+ fn serialize_newtype_struct<T: ?Sized>(
+ self,
+ _name: &'static str,
+ value: &T,
+ ) -> Result<InternalString, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ value.serialize(self)
+ }
+
+ fn serialize_newtype_variant<T: ?Sized>(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _value: &T,
+ ) -> Result<InternalString, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ Err(Error::KeyNotString)
+ }
+
+ 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> {
+ Err(Error::KeyNotString)
+ }
+
+ 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> {
+ Err(Error::KeyNotString)
+ }
+
+ 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> {
+ Err(Error::KeyNotString)
+ }
+
+ fn serialize_struct_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
+ Err(Error::KeyNotString)
+ }
+}
diff --git a/vendor/toml_edit-0.19.11/src/ser/map.rs b/vendor/toml_edit-0.19.11/src/ser/map.rs
new file mode 100644
index 000000000..d743e3d5d
--- /dev/null
+++ b/vendor/toml_edit-0.19.11/src/ser/map.rs
@@ -0,0 +1,405 @@
+use super::{Error, KeySerializer};
+
+#[doc(hidden)]
+pub enum SerializeMap {
+ Datetime(SerializeDatetime),
+ Table(SerializeInlineTable),
+}
+
+impl SerializeMap {
+ pub(crate) fn table() -> Self {
+ Self::Table(SerializeInlineTable::new())
+ }
+
+ pub(crate) fn table_with_capacity(len: usize) -> Self {
+ Self::Table(SerializeInlineTable::with_capacity(len))
+ }
+
+ pub(crate) fn datetime() -> Self {
+ Self::Datetime(SerializeDatetime::new())
+ }
+}
+
+impl serde::ser::SerializeMap for SerializeMap {
+ type Ok = crate::Value;
+ type Error = Error;
+
+ fn serialize_key<T: ?Sized>(&mut self, input: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ match self {
+ Self::Datetime(s) => s.serialize_key(input),
+ Self::Table(s) => s.serialize_key(input),
+ }
+ }
+
+ fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ match self {
+ Self::Datetime(s) => s.serialize_value(value),
+ Self::Table(s) => s.serialize_value(value),
+ }
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ match self {
+ Self::Datetime(s) => s.end().map(|items| items.into()),
+ Self::Table(s) => s.end().map(|items| items.into()),
+ }
+ }
+}
+
+impl serde::ser::SerializeStruct for SerializeMap {
+ type Ok = crate::Value;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized>(
+ &mut self,
+ key: &'static str,
+ value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ match self {
+ Self::Datetime(s) => s.serialize_field(key, value),
+ Self::Table(s) => s.serialize_field(key, value),
+ }
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ match self {
+ Self::Datetime(s) => s.end().map(|items| items.into()),
+ Self::Table(s) => s.end().map(|items| items.into()),
+ }
+ }
+}
+
+#[doc(hidden)]
+pub struct SerializeDatetime {
+ value: Option<crate::Datetime>,
+}
+
+impl SerializeDatetime {
+ pub(crate) fn new() -> Self {
+ Self { value: None }
+ }
+}
+
+impl serde::ser::SerializeMap for SerializeDatetime {
+ type Ok = crate::Datetime;
+ type Error = Error;
+
+ fn serialize_key<T: ?Sized>(&mut self, _input: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ unreachable!("datetimes should only be serialized as structs, not maps")
+ }
+
+ fn serialize_value<T: ?Sized>(&mut self, _value: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ unreachable!("datetimes should only be serialized as structs, not maps")
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ unreachable!("datetimes should only be serialized as structs, not maps")
+ }
+}
+
+impl serde::ser::SerializeStruct for SerializeDatetime {
+ type Ok = crate::Datetime;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized>(
+ &mut self,
+ key: &'static str,
+ value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ if key == toml_datetime::__unstable::FIELD {
+ self.value = Some(value.serialize(DatetimeFieldSerializer::default())?);
+ }
+
+ Ok(())
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ self.value.ok_or(Error::UnsupportedNone)
+ }
+}
+
+#[doc(hidden)]
+pub struct SerializeInlineTable {
+ items: crate::table::KeyValuePairs,
+ key: Option<crate::InternalString>,
+}
+
+impl SerializeInlineTable {
+ pub(crate) fn new() -> Self {
+ Self {
+ items: Default::default(),
+ key: Default::default(),
+ }
+ }
+
+ pub(crate) fn with_capacity(len: usize) -> Self {
+ let mut s = Self::new();
+ s.items.reserve(len);
+ s
+ }
+}
+
+impl serde::ser::SerializeMap for SerializeInlineTable {
+ type Ok = crate::InlineTable;
+ type Error = Error;
+
+ fn serialize_key<T: ?Sized>(&mut self, input: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ self.key = None;
+ self.key = Some(input.serialize(KeySerializer)?);
+ Ok(())
+ }
+
+ fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ let res = value.serialize(super::ValueSerializer {});
+ match res {
+ Ok(item) => {
+ let key = self.key.take().unwrap();
+ let kv = crate::table::TableKeyValue::new(
+ crate::Key::new(&key),
+ crate::Item::Value(item),
+ );
+ self.items.insert(key, kv);
+ }
+ Err(e) => {
+ if e != Error::UnsupportedNone {
+ return Err(e);
+ }
+ }
+ }
+ Ok(())
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ Ok(crate::InlineTable::with_pairs(self.items))
+ }
+}
+
+impl serde::ser::SerializeStruct for SerializeInlineTable {
+ type Ok = crate::InlineTable;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized>(
+ &mut self,
+ key: &'static str,
+ value: &T,
+ ) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ let res = value.serialize(super::ValueSerializer {});
+ match res {
+ Ok(item) => {
+ let kv = crate::table::TableKeyValue::new(
+ crate::Key::new(key),
+ crate::Item::Value(item),
+ );
+ self.items.insert(crate::InternalString::from(key), kv);
+ }
+ Err(e) => {
+ if e != Error::UnsupportedNone {
+ return Err(e);
+ }
+ }
+ };
+ Ok(())
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ Ok(crate::InlineTable::with_pairs(self.items))
+ }
+}
+
+#[derive(Default)]
+struct DatetimeFieldSerializer {}
+
+impl serde::ser::Serializer for DatetimeFieldSerializer {
+ type Ok = toml_datetime::Datetime;
+ type Error = Error;
+ type SerializeSeq = serde::ser::Impossible<Self::Ok, Self::Error>;
+ type SerializeTuple = serde::ser::Impossible<Self::Ok, Self::Error>;
+ type SerializeTupleStruct = serde::ser::Impossible<Self::Ok, Self::Error>;
+ type SerializeTupleVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
+ type SerializeMap = serde::ser::Impossible<Self::Ok, Self::Error>;
+ type SerializeStruct = serde::ser::Impossible<Self::Ok, Self::Error>;
+ type SerializeStructVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
+
+ fn serialize_bool(self, _value: bool) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_i8(self, _value: i8) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_i16(self, _value: i16) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_i32(self, _value: i32) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_i64(self, _value: i64) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_u8(self, _value: u8) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_u16(self, _value: u16) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_u32(self, _value: u32) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_u64(self, _value: u64) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_f32(self, _value: f32) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_f64(self, _value: f64) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_char(self, _value: char) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
+ v.parse::<toml_datetime::Datetime>().map_err(Error::custom)
+ }
+
+ fn serialize_bytes(self, _value: &[u8]) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_some<T: ?Sized>(self, _value: &T) -> Result<Self::Ok, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_unit_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ ) -> Result<Self::Ok, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_newtype_struct<T: ?Sized>(
+ self,
+ _name: &'static str,
+ _value: &T,
+ ) -> Result<Self::Ok, Self::Error>
+ where
+ T: serde::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::Ok, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ Err(Error::DateInvalid)
+ }
+
+ 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> {
+ Err(Error::DateInvalid)
+ }
+
+ 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> {
+ Err(Error::DateInvalid)
+ }
+
+ 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> {
+ Err(Error::DateInvalid)
+ }
+
+ fn serialize_struct_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
+ Err(Error::DateInvalid)
+ }
+}
diff --git a/vendor/toml_edit-0.19.11/src/ser/mod.rs b/vendor/toml_edit-0.19.11/src/ser/mod.rs
new file mode 100644
index 000000000..2c310206b
--- /dev/null
+++ b/vendor/toml_edit-0.19.11/src/ser/mod.rs
@@ -0,0 +1,165 @@
+//! Serializing Rust structures into TOML.
+//!
+//! This module contains all the Serde support for serializing Rust structures into TOML.
+
+mod array;
+mod key;
+mod map;
+mod pretty;
+mod value;
+
+pub(crate) use array::*;
+pub(crate) use key::*;
+pub(crate) use map::*;
+
+use crate::visit_mut::VisitMut;
+
+/// Errors that can occur when deserializing a type.
+#[derive(Debug, Clone, PartialEq, Eq)]
+#[non_exhaustive]
+pub enum Error {
+ /// Type could not be serialized to TOML
+ UnsupportedType(Option<&'static str>),
+ /// Value was out of range for the given type
+ OutOfRange(Option<&'static str>),
+ /// `None` could not be serialized to TOML
+ UnsupportedNone,
+ /// Key was not convertable to `String` for serializing to TOML
+ KeyNotString,
+ /// A serialized date was invalid
+ DateInvalid,
+ /// Other serialization error
+ Custom(String),
+}
+
+impl Error {
+ pub(crate) fn custom<T>(msg: T) -> Self
+ where
+ T: std::fmt::Display,
+ {
+ Error::Custom(msg.to_string())
+ }
+}
+
+impl serde::ser::Error for Error {
+ fn custom<T>(msg: T) -> Self
+ where
+ T: std::fmt::Display,
+ {
+ Self::custom(msg)
+ }
+}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
+ match self {
+ Self::UnsupportedType(Some(t)) => write!(formatter, "unsupported {t} type"),
+ Self::UnsupportedType(None) => write!(formatter, "unsupported rust type"),
+ Self::OutOfRange(Some(t)) => write!(formatter, "out-of-range value for {t} type"),
+ Self::OutOfRange(None) => write!(formatter, "out-of-range value"),
+ Self::UnsupportedNone => "unsupported None value".fmt(formatter),
+ Self::KeyNotString => "map key was not a string".fmt(formatter),
+ Self::DateInvalid => "a serialized date was invalid".fmt(formatter),
+ Self::Custom(s) => s.fmt(formatter),
+ }
+ }
+}
+
+impl From<crate::TomlError> for Error {
+ fn from(e: crate::TomlError) -> Error {
+ Self::custom(e)
+ }
+}
+
+impl From<Error> for crate::TomlError {
+ fn from(e: Error) -> crate::TomlError {
+ Self::custom(e.to_string(), None)
+ }
+}
+
+impl std::error::Error for Error {}
+
+/// Serialize the given data structure as a TOML byte vector.
+///
+/// Serialization can fail if `T`'s implementation of `Serialize` decides to
+/// 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: serde::ser::Serialize,
+{
+ to_string(value).map(|e| e.into_bytes())
+}
+
+/// Serialize the given data structure as a String of TOML.
+///
+/// Serialization can fail if `T`'s implementation of `Serialize` decides to
+/// 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.
+///
+/// # Examples
+///
+/// ```
+/// use serde::Serialize;
+///
+/// #[derive(Serialize)]
+/// struct Config {
+/// database: Database,
+/// }
+///
+/// #[derive(Serialize)]
+/// struct Database {
+/// ip: String,
+/// port: Vec<u16>,
+/// connection_max: u32,
+/// enabled: bool,
+/// }
+///
+/// let config = Config {
+/// database: Database {
+/// ip: "192.168.1.1".to_string(),
+/// port: vec![8001, 8002, 8003],
+/// connection_max: 5000,
+/// enabled: false,
+/// },
+/// };
+///
+/// let toml = toml_edit::ser::to_string(&config).unwrap();
+/// println!("{}", toml)
+/// ```
+pub fn to_string<T: ?Sized>(value: &T) -> Result<String, Error>
+where
+ T: serde::ser::Serialize,
+{
+ to_document(value).map(|e| e.to_string())
+}
+
+/// Serialize the given data structure as a "pretty" String of TOML.
+///
+/// This is identical to `to_string` except the output string has a more
+/// "pretty" output. See `ValueSerializer::pretty` for more details.
+pub fn to_string_pretty<T: ?Sized>(value: &T) -> Result<String, Error>
+where
+ T: serde::ser::Serialize,
+{
+ let mut document = to_document(value)?;
+ pretty::Pretty.visit_document_mut(&mut document);
+ Ok(document.to_string())
+}
+
+/// Serialize the given data structure into a TOML document.
+///
+/// This would allow custom formatting to be applied, mixing with format preserving edits, etc.
+pub fn to_document<T: ?Sized>(value: &T) -> Result<crate::Document, Error>
+where
+ T: serde::ser::Serialize,
+{
+ let value = value.serialize(ValueSerializer::new())?;
+ let item = crate::Item::Value(value);
+ let root = item
+ .into_table()
+ .map_err(|_| Error::UnsupportedType(None))?;
+ Ok(root.into())
+}
+
+pub use value::ValueSerializer;
diff --git a/vendor/toml_edit-0.19.11/src/ser/pretty.rs b/vendor/toml_edit-0.19.11/src/ser/pretty.rs
new file mode 100644
index 000000000..2c22f6804
--- /dev/null
+++ b/vendor/toml_edit-0.19.11/src/ser/pretty.rs
@@ -0,0 +1,45 @@
+pub(crate) struct Pretty;
+
+impl crate::visit_mut::VisitMut for Pretty {
+ fn visit_document_mut(&mut self, node: &mut crate::Document) {
+ crate::visit_mut::visit_document_mut(self, node);
+ }
+
+ fn visit_item_mut(&mut self, node: &mut crate::Item) {
+ node.make_item();
+
+ crate::visit_mut::visit_item_mut(self, node);
+ }
+
+ fn visit_table_mut(&mut self, node: &mut crate::Table) {
+ node.decor_mut().clear();
+
+ // Empty tables could be semantically meaningful, so make sure they are not implicit
+ if !node.is_empty() {
+ node.set_implicit(true);
+ }
+
+ crate::visit_mut::visit_table_mut(self, node);
+ }
+
+ fn visit_value_mut(&mut self, node: &mut crate::Value) {
+ node.decor_mut().clear();
+
+ crate::visit_mut::visit_value_mut(self, node);
+ }
+
+ fn visit_array_mut(&mut self, node: &mut crate::Array) {
+ crate::visit_mut::visit_array_mut(self, node);
+
+ if (0..=1).contains(&node.len()) {
+ node.set_trailing("");
+ node.set_trailing_comma(false);
+ } else {
+ for item in node.iter_mut() {
+ item.decor_mut().set_prefix("\n ");
+ }
+ node.set_trailing("\n");
+ node.set_trailing_comma(true);
+ }
+ }
+}
diff --git a/vendor/toml_edit-0.19.11/src/ser/value.rs b/vendor/toml_edit-0.19.11/src/ser/value.rs
new file mode 100644
index 000000000..d29390a4c
--- /dev/null
+++ b/vendor/toml_edit-0.19.11/src/ser/value.rs
@@ -0,0 +1,243 @@
+use super::Error;
+
+/// Serialization for TOML [values][crate::Value].
+///
+/// This structure implements serialization support for TOML to serialize an
+/// arbitrary type to TOML. Note that the TOML format does not support all
+/// datatypes in Rust, such as enums, tuples, and tuple structs. These types
+/// will generate an error when serialized.
+///
+/// Currently a serializer always writes its output to an in-memory `String`,
+/// which is passed in when creating the serializer itself.
+///
+/// # Examples
+///
+/// ```
+/// use serde::Serialize;
+///
+/// #[derive(Serialize)]
+/// struct Config {
+/// database: Database,
+/// }
+///
+/// #[derive(Serialize)]
+/// struct Database {
+/// ip: String,
+/// port: Vec<u16>,
+/// connection_max: u32,
+/// enabled: bool,
+/// }
+///
+/// let config = Config {
+/// database: Database {
+/// ip: "192.168.1.1".to_string(),
+/// port: vec![8001, 8002, 8003],
+/// connection_max: 5000,
+/// enabled: false,
+/// },
+/// };
+///
+/// let value = serde::Serialize::serialize(
+/// &config,
+/// toml_edit::ser::ValueSerializer::new()
+/// ).unwrap();
+/// println!("{}", value)
+/// ```
+#[derive(Default)]
+#[non_exhaustive]
+pub struct ValueSerializer {}
+
+impl ValueSerializer {
+ /// Creates a new serializer generate a TOML document.
+ pub fn new() -> Self {
+ Self {}
+ }
+}
+
+impl serde::ser::Serializer for ValueSerializer {
+ type Ok = crate::Value;
+ type Error = Error;
+ type SerializeSeq = super::SerializeValueArray;
+ type SerializeTuple = super::SerializeValueArray;
+ type SerializeTupleStruct = super::SerializeValueArray;
+ type SerializeTupleVariant = super::SerializeValueArray;
+ type SerializeMap = super::SerializeMap;
+ type SerializeStruct = super::SerializeMap;
+ type SerializeStructVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
+
+ fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
+ Ok(v.into())
+ }
+
+ fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
+ self.serialize_i64(v as i64)
+ }
+
+ fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
+ self.serialize_i64(v as i64)
+ }
+
+ fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
+ self.serialize_i64(v as i64)
+ }
+
+ fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
+ Ok(v.into())
+ }
+
+ fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
+ self.serialize_i64(v as i64)
+ }
+
+ fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
+ self.serialize_i64(v as i64)
+ }
+
+ fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
+ self.serialize_i64(v as i64)
+ }
+
+ fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
+ let v: i64 = v
+ .try_into()
+ .map_err(|_err| Error::OutOfRange(Some("u64")))?;
+ self.serialize_i64(v)
+ }
+
+ fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
+ self.serialize_f64(v as f64)
+ }
+
+ fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
+ Ok(v.into())
+ }
+
+ fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> {
+ let mut buf = [0; 4];
+ self.serialize_str(v.encode_utf8(&mut buf))
+ }
+
+ fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
+ Ok(v.into())
+ }
+
+ fn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Self::Error> {
+ use serde::ser::Serialize;
+ value.serialize(self)
+ }
+
+ fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
+ Err(Error::UnsupportedNone)
+ }
+
+ fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ value.serialize(self)
+ }
+
+ fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
+ Err(Error::UnsupportedType(Some("unit")))
+ }
+
+ fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> {
+ Err(Error::UnsupportedType(Some(name)))
+ }
+
+ fn serialize_unit_variant(
+ self,
+ _name: &'static str,
+ _variant_index: u32,
+ variant: &'static str,
+ ) -> Result<Self::Ok, Self::Error> {
+ self.serialize_str(variant)
+ }
+
+ fn serialize_newtype_struct<T: ?Sized>(
+ self,
+ _name: &'static str,
+ value: &T,
+ ) -> Result<Self::Ok, Self::Error>
+ where
+ T: serde::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::Ok, Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ let value = value.serialize(self)?;
+ let mut table = crate::InlineTable::new();
+ table.insert(variant, value);
+ Ok(table.into())
+ }
+
+ fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
+ let serializer = match len {
+ Some(len) => super::SerializeValueArray::with_capacity(len),
+ None => super::SerializeValueArray::new(),
+ };
+ Ok(serializer)
+ }
+
+ 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> {
+ 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> {
+ self.serialize_seq(Some(len))
+ }
+
+ fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
+ let serializer = match len {
+ Some(len) => super::SerializeMap::table_with_capacity(len),
+ None => super::SerializeMap::table(),
+ };
+ Ok(serializer)
+ }
+
+ fn serialize_struct(
+ self,
+ name: &'static str,
+ len: usize,
+ ) -> Result<Self::SerializeStruct, Self::Error> {
+ if name == toml_datetime::__unstable::NAME {
+ Ok(super::SerializeMap::datetime())
+ } else {
+ self.serialize_map(Some(len))
+ }
+ }
+
+ fn serialize_struct_variant(
+ self,
+ name: &'static str,
+ _variant_index: u32,
+ _variant: &'static str,
+ _len: usize,
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
+ Err(Error::UnsupportedType(Some(name)))
+ }
+}