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

Issue:
[feature] Table -> InlineTable
Hello! I'm trying to turn 
```toml
[site]
bucket = ""
entry-point = "workers-site"
```
into an inline table using toml_edit. Oddly enough, when I parse my toml, I get
```
Table(Table { items: {"bucket": TableKeyValue { key: Repr { decor: Decor { prefix: "", suffix: " " }, raw_value: "bucket" }, value: Value(String(Formatted { value: "", repr: Repr { decor: Decor { prefix: " ", suffix: "" }, raw_value: "\"\"" } })) }, "entry-point": TableKeyValue { key: Repr { decor: Decor { prefix: "", suffix: " " }, raw_value: "entry-point" }, value: Value(String(Formatted { value: "workers-site", repr: Repr { decor: Decor { prefix: " ", suffix: "" }, raw_value: "\"workers-site\"" } })) }}, decor: Decor { prefix: "\n", suffix: "" }, implicit: false, position: Some(1) })
```
Type `Table(Table...` was not I expected to see above, and I suspect it's why calling `.as_inline_table()` fails on the table provided above. (instead, calling `.as_inline_table()` returns `None`).

Any pieces of advice? :)


Discussion / hints:
hey @gabbifish! This is the expected output. Inline tables are something different: https://github.com/toml-lang/toml#user-content-inline-table.
For example,
```toml
site = { bucket = "", entry-point = "workers-site" }
```
This would be an equivalent inline table in your case. Does that make sense?
Ah, I see you're trying to convert a `Table` into an `InlineTable` and expecting `as_inline_table` to do the conversion. But that's not what it does. It performs a dynamic check and returns `Some(InlineTable)` if it's actually is an InlineTable.
Currently, the functionality you asking is missing: https://github.com/ordian/toml_edit/blob/b679b5e610b9a19f48fa0268f9174062e9c43962/src/table.rs#L8

PRs are welcome :)
Here is my snippet which converts `Table` into `InlineTable`:

```rust
fn make_inline_tbls(paths_arr: &mut ArrayOfTables) {
    for x in (0..paths_arr.len()) {
        let sub = paths_arr.get_mut(x).expect("");
        let tgt_raw = sub.entry("target");

        tgt_raw.as_inline_table_mut().map(|e| e.fmt());
        let tgt_table = tgt_raw.as_table().expect("");
        let mut tgt_inline = InlineTable::default();
        tgt_table.iter().for_each(|i| {
            let key = i.0;
            let value = i.1.as_value().expect("").to_owned();
            tgt_inline.get_or_insert(key, value);
        });
        tgt_inline.fmt();


        let mut tgt_val = Value::InlineTable(tgt_inline);
        let tgt_item = Item::Value(tgt_val);
        *tgt_raw = tgt_item;

    }
}
```

I'm not a rustacean, so, probably, this is a piece of crap, though it works. Would really like to see a built-in API.
The next release includes a `item.into_value()` which will turn a table into an inline table.  We don't have an in-place version yet, so you'll have to remove, convert, and insert.

Fix patch:
diff --git a/src/array.rs b/src/array.rs
index 40e51a13..a6b33862 100644
--- a/src/array.rs
+++ b/src/array.rs
@@ -41,7 +41,6 @@ impl Array {
         Default::default()
     }
 
-    #[cfg(feature = "easy")]
     pub(crate) fn with_vec(values: Vec<Item>) -> Self {
         Self {
             values,
diff --git a/src/array_of_tables.rs b/src/array_of_tables.rs
index ea3c25ec..6dc3c5f6 100644
--- a/src/array_of_tables.rs
+++ b/src/array_of_tables.rs
@@ -22,11 +22,11 @@ impl ArrayOfTables {
 /// Formatting
 impl ArrayOfTables {
     /// Convert to an inline array
-    pub fn into_array(self) -> Array {
-        self.values
-            .into_iter()
-            .filter_map(|i| i.into_value().ok())
-            .collect()
+    pub fn into_array(mut self) -> Array {
+        for value in self.values.iter_mut() {
+            value.make_value();
+        }
+        Array::with_vec(self.values)
     }
 }
 
diff --git a/src/inline_table.rs b/src/inline_table.rs
index 07609750..ff15b02a 100644
--- a/src/inline_table.rs
+++ b/src/inline_table.rs
@@ -28,7 +28,6 @@ impl InlineTable {
         Default::default()
     }
 
-    #[cfg(feature = "easy")]
     pub(crate) fn with_pairs(items: KeyValuePairs) -> Self {
         Self {
             items,
diff --git a/src/item.rs b/src/item.rs
index 53c8a801..4adb3086 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -92,6 +92,13 @@ impl Item {
             Item::ArrayOfTables(v) => Ok(Value::Array(v.into_array())),
         }
     }
+    /// In-place convert to a value
+    pub fn make_value(&mut self) {
+        let mut other = Item::None;
+        std::mem::swap(self, &mut other);
+        let mut other = other.into_value().map(Item::Value).unwrap_or(Item::None);
+        std::mem::swap(self, &mut other);
+    }
     /// Casts `self` to table.
     pub fn into_table(self) -> Result<Table, Self> {
         match self {
diff --git a/src/table.rs b/src/table.rs
index db002c11..8f56bf66 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -47,19 +47,11 @@ impl Table {
     }
 
     /// Convert to an inline array
-    pub fn into_inline_table(self) -> InlineTable {
-        let table: InlineTable = self
-            .items
-            .into_iter()
-            .filter_map(|(_, kv)| {
-                let mut k = kv.key;
-                k.decor_mut().clear();
-                let v = kv.value;
-                let v = v.into_value().ok()?;
-                Some((k, v))
-            })
-            .collect();
-        table
+    pub fn into_inline_table(mut self) -> InlineTable {
+        for (_, kv) in self.items.iter_mut() {
+            kv.value.make_value();
+        }
+        InlineTable::with_pairs(self.items)
     }
 }
 


Test patch: