Comments (4)
hey @gabbifish! This is the expected output. Inline tables are something different: https://github.com/toml-lang/toml#user-content-inline-table.
For example,
site = { bucket = "", entry-point = "workers-site" }
This would be an equivalent inline table in your case. Does that make sense?
from toml.
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 :)
from toml.
Here is my snippet which converts Table
into InlineTable
:
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.
from toml.
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.
from toml.
Related Issues (20)
- Fix u64 deserialization HOT 6
- Multi-line k/v pairs HOT 1
- Serialization of keys varies depending on whether the feature flag "parse" is enabled
- Array of Tables `remove` does not return the removed table
- Implement `From<inner type>` for `Item`
- Decor in `DocumentMut` is ignored HOT 2
- Feature proposal: Type-safe decor mutation API HOT 1
- Allow to create `Decor` instances with optional prefix or suffix
- How to serialize/deserialize while preserving formats with `toml_edit`? HOT 3
- [Bug] `de::from_str` has overly strict generic restrictions. HOT 1
- How to use `Spanned` HOT 1
- Missing output on `or_insert()`ing on a nested `Item::None` table HOT 3
- Function for inserting table key at ordinal in a `TableLike` HOT 1
- Bad span with untagged enum HOT 1
- Table::try_into / Value::try_into not working HOT 6
- Uneeded escapes with multiline string character escapes HOT 7
- Allow setting key's representation HOT 2
- Feature Request: get raw repr of key/value when deserializing HOT 5
- `toml_edit`: value is not written if table is constructed beforehand HOT 5
- Implement `Serialize` and `Deserialize` for `Date` and `Time` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toml.