Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_dotted(true) on InlineTable doesn't work as expected #233

Closed
ordian opened this issue Oct 13, 2021 · 5 comments · Fixed by #235
Closed

set_dotted(true) on InlineTable doesn't work as expected #233

ordian opened this issue Oct 13, 2021 · 5 comments · Fixed by #235

Comments

@ordian
Copy link
Member

ordian commented Oct 13, 2021

use toml_edit::*;

fn main() {
    let mut d = Document::new();
    d["nixpkgs"] = table();
    d["nixpkgs"]["src"]["git"] = value("https://git");
    d["nixpkgs"]["src"].as_inline_table_mut().unwrap().set_dotted(true);
    println!("{}", d);
}

prints

[nixpkgs]
src = { git = "https://git"}
@ordian
Copy link
Member Author

ordian commented Oct 13, 2021

Thinking about this, what's the difference between dotted InlineTable and dotted Table?

@steveej
Copy link

steveej commented Oct 13, 2021

i don't feel confident that i can help clear up the definitions, but i'd like to make my expectations explicit:

[nixpkgs]
src.git = "https://git"

i'm also wondering which table is considered dotted here 🤔 it seems to be a property of the keys in the nixpkgs table rather than in the src table.

@ordian
Copy link
Member Author

ordian commented Oct 13, 2021

[nixpkgs]
src.git = "https://git"

This is the expected output. And this code works:

use toml_edit::*;

fn main() {
    let mut d = Document::new();
    d["nixpkgs"] = table();
    
    d["nixpkgs"]["src"] = table();
    d["nixpkgs"]["src"].as_table_mut().unwrap().set_dotted(true);
    d["nixpkgs"]["src"]["git"] = value("https://github.com/nixos/nixpkgs");

    println!("{}", d);
}

@ordian
Copy link
Member Author

ordian commented Oct 13, 2021

i'm also wondering which table is considered dotted here thinking it seems to be a property of the keys in the nixpkgs table rather than in the src table.

This is a TOML property, so src is a table (dotted), and git is the key of that table, see https://toml.io/en/v1.0.0 for details.

EDIT: actually TOML spec talks about dotted keys, not tables. But I in terms implementation, it might be harder to implement as a property of keys.

@epage
Copy link
Member

epage commented Oct 14, 2021

Thinking about this, what's the difference between dotted InlineTable and dotted Table?

Ease of implementation :)

A dotted key in a standard table can have standard tables nested under it

[fruit]
apple.color = "red"
apple.taste.sweet = true

# [fruit.apple]  # INVALID
# [fruit.apple.taste]  # INVALID

[fruit.apple.texture]  # you can add sub-tables
smooth = true

But you can't do that with Inline Tables.

And the way the divide is currently implemented generally makes it easier to convert the data back to a string. I do have an idea that might allow us to fix this.

epage added a commit to epage/toml_edit that referenced this issue Oct 14, 2021
Before, we ignored the dotted-ness of it

Fixes toml-rs#233
epage added a commit that referenced this issue Oct 14, 2021
Before, we ignored the dotted-ness of it

Fixes #233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants