-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add some mutable accessors to Array #88
Conversation
The &mut isn't required.
@sunshowers thanks for the PR! I think the reason I omitted mutable accessors to Array is to enforce type-safety, so that it would be impossible to create an invalid toml document. In TOML Arrays contain values of the same data type https://github.com/toml-lang/toml#user-content-array, but with mutable accessors it would be possible e.g. to swap a string with a number as We already have a mutating function I don't know what would be the good solution here, will need to think about it. |
ahhh I see! Yeah that's a problem. Some ways I can think about resolving this:
The core problem I was trying to solve was change elements of an array while preserving existing formatting. |
Another way might be to return a wrapper around &mut Value instances that does validation for any replacement values. That might be a cleaner way to achieve the same goals, and the wrapper type would prevent mem::replace (which I was definitely using, heh) |
That sounds like an interesting idea to try, but I'm not quite sure how the mutating API would look like? It's possible already to get the value formatting with The reason Feel free to push commits implementing your ideas and I'll give you feedback. |
Another idea would be to implement a bunch of |
`Decor` in particular was exposed by an API but not exported.
The `bool` is probably not descriptive enough, and returning an error gives us a chance to return the value.
Add both formatted and regular versions of these methods. The regular replace method preserves existing formatting.
Thanks! I ended up adding methods to insert and replace values in an array, both formatted and unformatted versions. Let me know what you think! |
(These are breaking changes, I hope that's fine because I think |
Oh, and if you're curious what I'm using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
I wonder what happened to CI...
Let's try to summon
bors r+
Looks like it was a mistake on my part https://github.com/ordian/toml_edit/blob/520bfe2c81af48664cfe5de16f5357d931aa0832/.github/workflows/ci.yml#L3. |
Yeah, I wanted to change that myself, sometimes you look at your code that you wrote 3 years ago and wonder... :) |
Build succeeded: |
I found these to be quite convenient while working with
toml_edit
.(Could you also do a new release once this is accepted? Thanks!)