Struct toml_span::de_helpers::TableHelper
source · pub struct TableHelper<'de> {
pub table: Table<'de>,
pub errors: Vec<Error>,
/* private fields */
}
Expand description
A helper for dealing with ValueInner::Table
Fields§
§table: Table<'de>
The table the helper is operating upon
errors: Vec<Error>
The errors accumulated while deserializing
Implementations§
source§impl<'de> TableHelper<'de>
impl<'de> TableHelper<'de>
sourcepub fn new(value: &mut Value<'de>) -> Result<Self, DeserError>
pub fn new(value: &mut Value<'de>) -> Result<Self, DeserError>
Creates a helper for the value, failing if it is not a table
sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true if the table contains the specified key
sourcepub fn take(&mut self, name: &'static str) -> Option<(Key<'de>, Value<'de>)>
pub fn take(&mut self, name: &'static str) -> Option<(Key<'de>, Value<'de>)>
Takes the specified key and its value if it exists
sourcepub fn required<T: Deserialize<'de>>(
&mut self,
name: &'static str,
) -> Result<T, Error>
pub fn required<T: Deserialize<'de>>( &mut self, name: &'static str, ) -> Result<T, Error>
Attempts to deserialize the specified key
Errors that occur when calling this method are automatically added to
the set of errors that are reported from Self::finalize
, so not early
returning if this method fails will still report the error by default
§Errors
- The key does not exist
- The
Deserialize
implementation for the type returns an error
sourcepub fn required_s<T: Deserialize<'de>>(
&mut self,
name: &'static str,
) -> Result<Spanned<T>, Error>
pub fn required_s<T: Deserialize<'de>>( &mut self, name: &'static str, ) -> Result<Spanned<T>, Error>
The same as Self::required
, except it returns a Spanned
sourcepub fn optional<T: Deserialize<'de>>(&mut self, name: &'static str) -> Option<T>
pub fn optional<T: Deserialize<'de>>(&mut self, name: &'static str) -> Option<T>
Attempts to deserialize the specified key, if it exists
Note that if the key exists but deserialization fails, an error will be
appended and if Self::finalize
is called it will return that error
along with any others that occurred
sourcepub fn optional_s<T: Deserialize<'de>>(
&mut self,
name: &'static str,
) -> Option<Spanned<T>>
pub fn optional_s<T: Deserialize<'de>>( &mut self, name: &'static str, ) -> Option<Spanned<T>>
The same as Self::optional
, except it returns a Spanned
sourcepub fn finalize(
self,
original: Option<&mut Value<'de>>,
) -> Result<(), DeserError>
pub fn finalize( self, original: Option<&mut Value<'de>>, ) -> Result<(), DeserError>
Called when you are finished with this TableHelper
If errors have been accumulated when using this TableHelper
, this will
return an error with all of those errors.
Additionally, if Option::None
is passed, any keys that still exist
in the table will be added to an ErrorKind::UnexpectedKeys
error,
which can be considered equivalent to #[serde(deny_unknown_fields)]
If you want simulate #[serde(flatten)]
you can instead put that table back in its original value during this step