pub trait Deserialize<'de>: Sized {
// Required method
fn deserialize(item: &mut Item<'de>) -> Result<Self, Error>;
}Expand description
Converts a parsed TOML Item into a typed Rust value.
Implement this trait on your own types to extract them from a parsed TOML
document via Table::required and Table::optional.
Built-in implementations are provided for common types: bool, integer
types (i8 through i64, u8 through u64, usize),
floating-point types (f32, f64), String,
Cow<'de, str>, [Str], Vec<T>, and
Spanned<T>.
§Examples
use toml_spanner::{Deserialize, Error, Item};
struct Endpoint {
host: String,
port: u16,
}
impl<'de> Deserialize<'de> for Endpoint {
fn deserialize(item: &mut Item<'de>) -> Result<Self, Error> {
let table = item.expect_table()?;
Ok(Endpoint {
host: table.required("host")?,
port: table.required("port")?,
})
}
}Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.