Repository: toml-rs/toml (language: rust)

Issue:
How do I replace `toml_edit::de::from_item`?
I have a function that does this:

```rust
fn my_fn(...) -> Result<MySerdeType> {
    ...
    if let Some(table) = doc.remove("toplevel-key") {
        Ok(toml_edit::de::from_item(table)?)
    } else {
        ...
    }
}
```

With the new toml_edit that removed `from_item`, how do I do this? I see from the changelog that I'm supposed to use `toml_edit::de::ValueDeserializer` somehow but I couldn't figure out how to wire things up...


Discussion / hints:

Fix patch:
diff --git a/crates/toml_edit/src/de/mod.rs b/crates/toml_edit/src/de/mod.rs
index 108f692b..efd95a25 100644
--- a/crates/toml_edit/src/de/mod.rs
+++ b/crates/toml_edit/src/de/mod.rs
@@ -122,7 +122,7 @@ where
     T::deserialize(deserializer)
 }
 
-/// Deserialization implementation for TOML.
+/// Deserialization for TOML [documents][crate::Document].
 pub struct Deserializer {
     input: crate::Document,
 }
diff --git a/crates/toml_edit/src/de/value.rs b/crates/toml_edit/src/de/value.rs
index 9a281610..5726feb9 100644
--- a/crates/toml_edit/src/de/value.rs
+++ b/crates/toml_edit/src/de/value.rs
@@ -3,7 +3,31 @@ use serde::de::IntoDeserializer as _;
 use crate::de::DatetimeDeserializer;
 use crate::de::Error;
 
-/// Deserialization implementation for TOML.
+/// Deserialization implementation for TOML [values][crate::Value].
+///
+/// # Example
+///
+/// ```
+/// use serde::Deserialize;
+///
+/// #[derive(Deserialize)]
+/// struct Config {
+///     title: String,
+///     owner: Owner,
+/// }
+///
+/// #[derive(Deserialize)]
+/// struct Owner {
+///     name: String,
+/// }
+///
+/// let value = r#"{ title = 'TOML Example', owner = { name = 'Lisa' } }"#;
+/// let deserializer = value.parse::<toml_edit::de::ValueDeserializer>().unwrap();
+/// let config = Config::deserialize(deserializer).unwrap();
+///
+/// assert_eq!(config.title, "TOML Example");
+/// assert_eq!(config.owner.name, "Lisa");
+/// ```
 pub struct ValueDeserializer {
     input: crate::Item,
     validate_struct_keys: bool,
diff --git a/crates/toml_edit/src/ser/value.rs b/crates/toml_edit/src/ser/value.rs
index 39598965..f0f30401 100644
--- a/crates/toml_edit/src/ser/value.rs
+++ b/crates/toml_edit/src/ser/value.rs
@@ -1,6 +1,6 @@
 use super::Error;
 
-/// Serialization implementation for TOML.
+/// Serialization for TOML [values][crate::Value].
 ///
 /// This structure implements serialization support for TOML to serialize an
 /// arbitrary type to TOML. Note that the TOML format does not support all
@@ -9,6 +9,40 @@ use super::Error;
 ///
 /// Currently a serializer always writes its output to an in-memory `String`,
 /// which is passed in when creating the serializer itself.
+///
+/// # Examples
+///
+/// ```
+/// use serde::Serialize;
+///
+/// #[derive(Serialize)]
+/// struct Config {
+///     database: Database,
+/// }
+///
+/// #[derive(Serialize)]
+/// struct Database {
+///     ip: String,
+///     port: Vec<u16>,
+///     connection_max: u32,
+///     enabled: bool,
+/// }
+///
+/// let config = Config {
+///     database: Database {
+///         ip: "192.168.1.1".to_string(),
+///         port: vec![8001, 8002, 8003],
+///         connection_max: 5000,
+///         enabled: false,
+///     },
+/// };
+///
+/// let value = serde::Serialize::serialize(
+///     &config,
+///     toml_edit::ser::ValueSerializer::new()
+/// ).unwrap();
+/// println!("{}", value)
+/// ```
 #[derive(Default)]
 #[non_exhaustive]
 pub struct ValueSerializer {}


Test patch: