9 /// Type representing a TOML table, payload of the `Value::Table` variant.
10 /// By default it is backed by a BTreeMap, enable the `preserve_order` feature
11 /// to use a LinkedHashMap instead.
12 pub type Table
= Map
<String
, Value
>;
15 /// Convert a `T` into `toml::Table`.
17 /// This conversion can fail if `T`'s implementation of `Serialize` decides to
18 /// fail, or if `T` contains a map with non-string keys.
19 pub fn try_from
<T
>(value
: T
) -> Result
<Self, crate::ser
::Error
>
23 value
.serialize(crate::value
::TableSerializer
)
26 /// Interpret a `toml::Table` as an instance of type `T`.
28 /// This conversion can fail if the structure of the `Table` does not match the structure
29 /// expected by `T`, for example if `T` is a bool which can't be mapped to a `Table`. It can
30 /// also fail if the structure is correct but `T`'s implementation of `Deserialize` decides
31 /// that something is wrong with the data, for example required struct fields are missing from
32 /// the TOML map or some number is too big to fit in the expected primitive type.
33 pub fn try_into
<'de
, T
>(self) -> Result
<T
, crate::de
::Error
>
35 T
: de
::Deserialize
<'de
>,
37 de
::Deserialize
::deserialize(self)
41 #[cfg(feature = "display")]
42 impl fmt
::Display
for Table
{
43 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
44 crate::ser
::to_string(self)
45 .expect("Unable to represent value as string")
50 #[cfg(feature = "parse")]
51 impl std
::str::FromStr
for Table
{
52 type Err
= crate::de
::Error
;
53 fn from_str(s
: &str) -> Result
<Self, Self::Err
> {
58 impl<'de
> de
::Deserializer
<'de
> for Table
{
59 type Error
= crate::de
::Error
;
61 fn deserialize_any
<V
>(self, visitor
: V
) -> Result
<V
::Value
, crate::de
::Error
>
65 Value
::Table(self).deserialize_any(visitor
)
69 fn deserialize_enum
<V
>(
72 variants
: &'
static [&'
static str],
74 ) -> Result
<V
::Value
, crate::de
::Error
>
78 Value
::Table(self).deserialize_enum(name
, variants
, visitor
)
81 // `None` is interpreted as a missing field so be sure to implement `Some`
82 // as a present field.
83 fn deserialize_option
<V
>(self, visitor
: V
) -> Result
<V
::Value
, crate::de
::Error
>
87 Value
::Table(self).deserialize_option(visitor
)
90 fn deserialize_newtype_struct
<V
>(
94 ) -> Result
<V
::Value
, crate::de
::Error
>
98 Value
::Table(self).deserialize_newtype_struct(name
, visitor
)
101 serde
::forward_to_deserialize_any
! {
102 bool
u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
103 bytes byte_buf map unit_struct tuple_struct
struct
104 tuple ignored_any identifier
108 impl<'de
> de
::IntoDeserializer
<'de
, crate::de
::Error
> for Table
{
109 type Deserializer
= Self;
111 fn into_deserializer(self) -> Self {