/// Type representing a TOML table, payload of the `Value::Table` variant. /// /// By default it entries are stored in /// [lexicographic order](https://doc.rust-lang.org/std/primitive.str.html#impl-Ord-for-str) /// of the keys. Enable the `preserve_order` feature to store entries in the order they appear in /// the source file. pubtype Table = Map<String, Value>;
impl Table { /// Convert a `T` into `toml::Table`. /// /// This conversion can fail if `T`'s implementation of `Serialize` decides to /// fail, or if `T` contains a map with non-string keys. pubfn try_from<T>(value: T) -> Result<Self, crate::ser::Error> where
T: ser::Serialize,
{
value.serialize(TableSerializer)
}
/// Interpret a `toml::Table` as an instance of type `T`. /// /// This conversion can fail if the structure of the `Table` does not match the structure /// expected by `T`, for example if `T` is a bool which can't be mapped to a `Table`. It can /// also fail if the structure is correct but `T`'s implementation of `Deserialize` decides /// that something is wrong with the data, for example required struct fields are missing from /// the TOML map or some number is too big to fit in the expected primitive type. pubfn try_into<'de, T>(self) -> Result<T, crate::de::Error> where
T: de::Deserialize<'de>,
{
de::Deserialize::deserialize(self)
}
}
#[cfg(feature = "display")] impl core::fmt::Display for Table { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { crate::ser::to_string(self)
.expect("Unable to represent value as string")
.fmt(f)
}
}
#[cfg(feature = "parse")] impl core::str::FromStr for Table { type Err = crate::de::Error; fn from_str(s: &str) -> Result<Self, Self::Err> { crate::from_str(s)
}
} impl ser::Serialize for Table { #[inline] fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: ser::Serializer,
{ use serde_core::ser::SerializeMap; letmut map = serializer.serialize_map(Some(self.len()))?; for (k, v) inself {
map.serialize_key(k)?;
map.serialize_value(v)?;
}
map.end()
}
}
impl<'de> de::Deserialize<'de> for Table { #[inline] fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: de::Deserializer<'de>,
{ struct Visitor;
impl<'de> de::Visitor<'de> for Visitor { type Value = Map<String, Value>;
// `None` is interpreted as a missing field so be sure to implement `Some` // as a present field. fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, crate::de::Error> where
V: de::Visitor<'de>,
{
Value::Table(self).deserialize_option(visitor)
}
impl de::IntoDeserializer<'_, crate::de::Error> for Table { type Deserializer = Self;
fn into_deserializer(self) -> Self { self
}
}
pub(crate) struct TableSerializer;
impl ser::Serializer for TableSerializer { type Ok = Table; type Error = crate::ser::Error;
type SerializeSeq = ser::Impossible<Self::Ok, Self::Error>; type SerializeTuple = ser::Impossible<Self::Ok, Self::Error>; type SerializeTupleStruct = ser::Impossible<Self::Ok, Self::Error>; type SerializeTupleVariant = ser::Impossible<Self::Ok, Self::Error>; type SerializeMap = SerializeMap; type SerializeStruct = SerializeMap; type SerializeStructVariant = ser::Impossible<Self::Ok, Self::Error>;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.