Closed teythoon closed 6 days ago
Further, the documentation says it returns a formatted value.
This seems to be either an oversight from a previous refactoring, or an ingenious attempt of gaslighting downstream consumers ;)
Neither. It is doing what its saying. It says
Returns a formatted value.
In contrast to
Returns a formatted
Value
.
In TOML semantics, it is returning a value and that is carried over in it being an Item::Value
.
The API is optimized for DocumentMut::index_mut
and Table::index_mut
for quick creation of a document, rather than any calls on InlineTable
or Array
.
e.g. code like https://github.com/toml-rs/toml/blob/0b4cf74420cc65e04e909945f48a36a19370327c/crates/toml_edit/tests/testsuite/edit.rs#L166-L168
As a new user of toml_edit, the most challenging aspect of its API was that it is so inhomogeneous. Depending on what kind of object you have, doing a get
or an iter
may give you Item
s, Array
s, or Value
s. That is a significant cognitive burden.
On top of that, having a function called value that returns an item doesn't help.
get
and iter
are generally returning the most specific types which gives you type level feedback on what you can do, rather than having to assume and unwrap
.
Doing this is fairly idiomatic in Rust. It is made worse by TOML having two different kinds of arrays and tables.
value
doesn't because it was generally geared for a different purpose (inserting into Tables)
At this time, I do not see us changing this part of the API
Further, the documentation says it returns a formatted value.
This seems to be either an oversight from a previous refactoring, or an ingenious attempt of gaslighting downstream consumers ;)