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

Issue:
`toml_edit` cannot collect an iterator over (key, item) pairs into `Table`
Because `impl<K: Into<Key>, V: Into<Value>> FromIterator<(K, V)> for Table` wants `Value`s even though `Table` stores `Item`s:

```rust
let source = Table::new();
let table_like = &source as &dyn toml_edit::TableLike;

// Doesn't work:
let table = table_like.iter().collect::<Table>();
//                            -------   ^^^^^ the trait `From<&toml_edit::Item>` is not implemented for `toml_edit::Value`, which is required by `toml_edit::Table: FromIterator<(&str, &toml_edit::Item)>`
//                            |
//                            required by a bound introduced by this call


// Instead, we have to use a workaround:
let mut table = Table::new();
table_like.iter().for_each(|(k, v)| { table.insert(k, v.clone()); });
```


Discussion / hints:

Fix patch:
diff --git a/crates/toml_edit/src/item.rs b/crates/toml_edit/src/item.rs
index 601c2358..75bfcdc1 100644
--- a/crates/toml_edit/src/item.rs
+++ b/crates/toml_edit/src/item.rs
@@ -342,6 +342,18 @@ impl FromStr for Item {
     }
 }
 
+impl<'b> From<&'b Item> for Item {
+    fn from(s: &'b Item) -> Self {
+        s.clone()
+    }
+}
+
+impl<V: Into<Value>> From<V> for Item {
+    fn from(s: V) -> Self {
+        Item::Value(s.into())
+    }
+}
+
 #[cfg(feature = "display")]
 impl std::fmt::Display for Item {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
diff --git a/crates/toml_edit/src/table.rs b/crates/toml_edit/src/table.rs
index 0238b2b7..c90298f5 100644
--- a/crates/toml_edit/src/table.rs
+++ b/crates/toml_edit/src/table.rs
@@ -442,17 +442,17 @@ impl std::fmt::Display for Table {
     }
 }
 
-impl<K: Into<Key>, V: Into<Value>> Extend<(K, V)> for Table {
+impl<K: Into<Key>, V: Into<Item>> Extend<(K, V)> for Table {
     fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
         for (key, value) in iter {
             let key = key.into();
-            let value = Item::Value(value.into());
+            let value = value.into();
             self.items.insert(key, value);
         }
     }
 }
 
-impl<K: Into<Key>, V: Into<Value>> FromIterator<(K, V)> for Table {
+impl<K: Into<Key>, V: Into<Item>> FromIterator<(K, V)> for Table {
     fn from_iter<I>(iter: I) -> Self
     where
         I: IntoIterator<Item = (K, V)>,


Test patch: