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

Function for inserting table key at ordinal in a TableLike #747

Open
nathaniel-daniel opened this issue Jul 4, 2024 · 1 comment
Open
Labels
A-edit Area: TOML editing API C-enhancement Category: Raise on the bar on expectations

Comments

@nathaniel-daniel
Copy link

Hello, I would like a function that would allow me to insert a key at a specified ordinal in a TableLike. I have a program that accepts a config file like the following (example):

[user]
first = "John"
last = "Doe"

Then my program will generate a key which is considered more "important" than the others, and I would like to place it at the top like so:

[user]
id = "John-Doe-1234"
first = "John"
last = "Doe"

However, there doesn't seem to be an api to control the insertion order of keys in a TableLike. Furthermore, a TableLike doesn't have a sort_values_by method. Combined, I don't believe there is a way to control entry order in a TableLike at all. Would it be possible to add some functionality to give users more control over entry order in a TableLike, or provide some control over the insertion location?

@epage
Copy link
Member

epage commented Jul 5, 2024

For inspiration, IndexMap exposes

  • shift_insert
    • We don't expose the concept of shift vs swap so we'd need another way to differentiate this
  • get_index
  • get_index_mut
  • get_index_entry
  • shift_remove_index
  • index
  • index_mut

For tables, we call it position, rather than index.

@epage epage added C-enhancement Category: Raise on the bar on expectations A-edit Area: TOML editing API labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edit Area: TOML editing API C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants