GithubHelp home page GithubHelp logo

[feature] Table -> InlineTable about toml HOT 4 CLOSED

toml-rs avatar toml-rs commented on August 23, 2024 1
[feature] Table -> InlineTable

from toml.

Comments (4)

ordian avatar ordian commented on August 23, 2024

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.

ordian avatar ordian commented on August 23, 2024

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.

pshirshov avatar pshirshov commented on August 23, 2024

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.

epage avatar epage commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.