Repository: toml-rs/toml
Pull request #931 (2025-06-06 18:54:49)

fix!: Various fixes


Patch:
diff --git a/crates/toml/src/value.rs b/crates/toml/src/value.rs
index 77db874b..5a72a44a 100644
--- a/crates/toml/src/value.rs
+++ b/crates/toml/src/value.rs
@@ -391,7 +391,8 @@ impl fmt::Display for Value {
 impl std::str::FromStr for Value {
     type Err = crate::de::Error;
     fn from_str(s: &str) -> Result<Value, Self::Err> {
-        crate::from_str(s)
+        use serde::Deserialize as _;
+        Value::deserialize(crate::de::ValueDeserializer::new(s))
     }
 }
 
diff --git a/crates/toml_edit/src/array.rs b/crates/toml_edit/src/array.rs
index bcd2b961..7702e952 100644
--- a/crates/toml_edit/src/array.rs
+++ b/crates/toml_edit/src/array.rs
@@ -174,9 +174,7 @@ impl Array {
     /// arr.push("foo");
     /// ```
     pub fn push<V: Into<Value>>(&mut self, v: V) {
-        self.value_op(v.into(), true, |items, value| {
-            items.push(Item::Value(value));
-        });
+        self.values.push(Item::Value(v.into()));
     }
 
     /// Appends a new, already formatted value to the end of the array.
@@ -211,9 +209,7 @@ impl Array {
     /// arr.insert(0, "start");
     /// ```
     pub fn insert<V: Into<Value>>(&mut self, index: usize, v: V) {
-        self.value_op(v.into(), true, |items, value| {
-            items.insert(index, Item::Value(value));
-        });
+        self.values.insert(index, Item::Value(v.into()));
     }
 
     /// Inserts an already formatted value at the given position within the array, shifting all
@@ -373,21 +369,6 @@ impl Array {
             }
         });
     }
-
-    fn value_op<T>(
-        &mut self,
-        v: Value,
-        decorate: bool,
-        op: impl FnOnce(&mut Vec<Item>, Value) -> T,
-    ) -> T {
-        let mut value = v;
-        if !self.is_empty() && decorate {
-            value.decorate(" ", "");
-        } else if decorate {
-            value.decorate("", "");
-        }
-        op(&mut self.values, value)
-    }
 }
 
 #[cfg(feature = "display")]
diff --git a/crates/toml_edit/src/array_of_tables.rs b/crates/toml_edit/src/array_of_tables.rs
index 22f3fb25..f2b74dcb 100644
--- a/crates/toml_edit/src/array_of_tables.rs
+++ b/crates/toml_edit/src/array_of_tables.rs
@@ -90,8 +90,11 @@ impl ArrayOfTables {
     }
 
     /// Removes a table with the given index.
-    pub fn remove(&mut self, index: usize) {
-        self.values.remove(index);
+    pub fn remove(&mut self, index: usize) -> Table {
+        self.values
+            .remove(index)
+            .into_table()
+            .expect("cannot have any other item in an array-of-tables")
     }
 
     /// Retains only the elements specified by the `keep` predicate.


Test patch:
diff --git a/crates/toml/tests/compliance/main.rs b/crates/toml/tests/compliance/main.rs
index 2f0138a4..4019cb5e 100644
--- a/crates/toml/tests/compliance/main.rs
+++ b/crates/toml/tests/compliance/main.rs
@@ -4,8 +4,7 @@
 
 macro_rules! parse_value {
     ($s:expr) => {{
-        use serde::Deserialize;
-        let v = toml::Value::deserialize(toml::de::ValueDeserializer::new($s));
+        let v = $s.parse::<toml::Value>();
         assert!(
             v.is_ok(),
             "Failed with `{}` when parsing: