/// [`from_str_radix`][i64::from_str_radix]-compatible representation of an integer /// /// Requires [`DeInteger::radix`] to interpret /// /// See [`Display`][std::fmt::Display] for a representation that includes the radix pubfn as_str(&self) -> &str { self.inner.as_ref()
}
/// Numeric base of [`DeInteger::as_str`] pubfn radix(&self) -> u32 { self.radix
}
}
/// Representation of a TOML value. #[derive(Clone, Debug)] pubenum DeValue<'i> { /// Represents a TOML string
String(DeString<'i>), /// Represents a TOML integer
Integer(DeInteger<'i>), /// Represents a TOML float
Float(DeFloat<'i>), /// Represents a TOML boolean
Boolean(bool), /// Represents a TOML datetime
Datetime(Datetime), /// Represents a TOML array
Array(DeArray<'i>), /// Represents a TOML table
Table(DeTable<'i>),
}
impl<'i> DeValue<'i> { /// Parse a TOML value pubfn parse(input: &'i str) -> Result<Spanned<Self>, crate::de::Error> { let source = toml_parser::Source::new(input); letmut errors = crate::de::error::TomlSink::<Option<_>>::new(source); let value = crate::de::parser::parse_value(source, &mut errors); iflet Some(err) = errors.into_inner() {
Err(err)
} else {
Ok(value)
}
}
/// Parse a TOML value, with best effort recovery on error pubfn parse_recoverable(input: &'i str) -> (Spanned<Self>, Vec<crate::de::Error>) { let source = toml_parser::Source::new(input); letmut errors = crate::de::error::TomlSink::<Vec<_>>::new(source); let value = crate::de::parser::parse_value(source, &mut errors);
(value, errors.into_inner())
}
/// Ensure no data is borrowed pubfn make_owned(&mutself) { matchself {
DeValue::String(v) => { let owned = core::mem::take(v);
*v = Cow::Owned(owned.into_owned());
}
DeValue::Integer(..)
| DeValue::Float(..)
| DeValue::Boolean(..)
| DeValue::Datetime(..) => {}
DeValue::Array(v) => { for e in v.iter_mut() {
e.get_mut().make_owned();
}
}
DeValue::Table(v) => v.make_owned(),
}
}
/// Index into a TOML array or map. A string index can be used to access a /// value in a map, and a usize index can be used to access an element of an /// array. /// /// Returns `None` if the type of `self` does not match the type of the /// index, for example if the index is a string and `self` is an array or a /// number. Also returns `None` if the given key does not exist in the map /// or the given index is not within the bounds of the array. pubfn get<I: Index>(&self, index: I) -> Option<&Spanned<Self>> {
index.index(self)
}
/// Extracts the integer value if it is an integer. pubfn as_integer(&self) -> Option<&DeInteger<'i>> { matchself {
DeValue::Integer(i) => Some(i),
_ => None,
}
}
/// Tests whether this value is an integer. pubfn is_integer(&self) -> bool { self.as_integer().is_some()
}
/// Extracts the float value if it is a float. pubfn as_float(&self) -> Option<&DeFloat<'i>> { matchself {
DeValue::Float(f) => Some(f),
_ => None,
}
}
/// Tests whether this value is a float. pubfn is_float(&self) -> bool { self.as_float().is_some()
}
/// Extracts the boolean value if it is a boolean. pubfn as_bool(&self) -> Option<bool> { match *self {
DeValue::Boolean(b) => Some(b),
_ => None,
}
}
/// Tests whether this value is a boolean. pubfn is_bool(&self) -> bool { self.as_bool().is_some()
}
/// Extracts the string of this value if it is a string. pubfn as_str(&self) -> Option<&str> { match *self {
DeValue::String(ref s) => Some(&**s),
_ => None,
}
}
/// Tests if this value is a string. pubfn is_str(&self) -> bool { self.as_str().is_some()
}
/// Extracts the datetime value if it is a datetime. /// /// Note that a parsed TOML value will only contain ISO 8601 dates. An /// example date is: /// /// ```notrust /// 1979-05-27T07:32:00Z /// ``` pubfn as_datetime(&self) -> Option<&Datetime> { match *self {
DeValue::Datetime(ref s) => Some(s),
_ => None,
}
}
/// Tests whether this value is a datetime. pubfn is_datetime(&self) -> bool { self.as_datetime().is_some()
}
/// Extracts the array value if it is an array. pubfn as_array(&self) -> Option<&DeArray<'i>> { match *self {
DeValue::Array(ref s) => Some(s),
_ => None,
}
}
/// Tests whether this value is an array. pubfn is_array(&self) -> bool { self.as_array().is_some()
}
/// Extracts the table value if it is a table. pubfn as_table(&self) -> Option<&DeTable<'i>> { match *self {
DeValue::Table(ref s) => Some(s),
_ => None,
}
}
/// Tests whether this value is a table. pubfn is_table(&self) -> bool { self.as_table().is_some()
}
/// Tests whether this and another value have the same type. pubfn same_type(&self, other: &DeValue<'_>) -> bool {
discriminant(self) == discriminant(other)
}
/// Returns a human-readable representation of the type of this value. pubfn type_str(&self) -> &'static str { match *self {
DeValue::String(..) => "string",
DeValue::Integer(..) => "integer",
DeValue::Float(..) => "float",
DeValue::Boolean(..) => "boolean",
DeValue::Datetime(..) => "datetime",
DeValue::Array(..) => "array",
DeValue::Table(..) => "table",
}
}
}
impl<I> ops::Index<I> for DeValue<'_> where
I: Index,
{ type Output = Spanned<Self>;
/// Types that can be used to index a `toml::Value` /// /// Currently this is implemented for `usize` to index arrays and `str` to index /// tables. /// /// This trait is sealed and not intended for implementation outside of the /// `toml` crate. pubtrait Index: Sealed { #[doc(hidden)] fn index<'r, 'i>(&self, val: &'r DeValue<'i>) -> Option<&'r Spanned<DeValue<'i>>>;
}
/// An implementation detail that should not be implemented, this will change in /// the future and break code otherwise. #[doc(hidden)] pubtrait Sealed {} impl Sealed for usize {} impl Sealed for str {} impl Sealed for String {} impl<T: Sealed + ?Sized> Sealed for &T {}
impl Index for usize { fn index<'r, 'i>(&self, val: &'r DeValue<'i>) -> Option<&'r Spanned<DeValue<'i>>> { match *val {
DeValue::Array(ref a) => a.get(*self),
_ => None,
}
}
}
impl Index for str { fn index<'r, 'i>(&self, val: &'r DeValue<'i>) -> Option<&'r Spanned<DeValue<'i>>> { match *val {
DeValue::Table(ref a) => a.get(self),
_ => None,
}
}
}
impl Index for String { fn index<'r, 'i>(&self, val: &'r DeValue<'i>) -> Option<&'r Spanned<DeValue<'i>>> { self[..].index(val)
}
}
impl<T> Index for &T where
T: Index + ?Sized,
{ fn index<'r, 'i>(&self, val: &'r DeValue<'i>) -> Option<&'r Spanned<DeValue<'i>>> {
(**self).index(val)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-08-27)
¤
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.