Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Deserializing struct enum from inline table works with from_str but not from toml::Value #470

Closed
mehmetalianil opened this issue Aug 3, 2022 · 2 comments

Comments

@mehmetalianil
Copy link

I was trying to have a workaround against nested enums, and ended up with this idea of parsing a toml, but leaving parts of it that are nested as toml::Value, to be parsed (or converted with try_into()) to the enum of my choice.

I realized that an inline table enum { KeepLast = { depth = 3 }} is successfully parsed with from_str but not when it is first deserialized into a toml::Value, and then parsed.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c3ed207a481ed3cac8aca7a56458f0fa

Keener eyes then mine in the Matrix room #rust:matrix.org have chipped in as:

The problem is that deserializing an enum from TOML text works differently than deserializing an enum from a Value.

text: https://docs.rs/toml/0.5.9/src/toml/de.rs.html#247-291
Value: https://docs.rs/toml/0.5.9/src/toml/value.rs.html#584-600

The text Deserializer allows both uninhabited enums (represented as a TOML string) and inhabited enums (represented as a table with one element), while the Value Deserializer only allows uninhabited enums. Worth opening an issue about, imo.

@axos88
Copy link

axos88 commented Sep 3, 2022

Related (sill wip): #473

@epage
Copy link
Member

epage commented Sep 23, 2022

Maintenance of this crate has moved to the https://github.com/toml-rs/toml repo. As a heads up, we plan to move toml to be on top of toml_edit, see toml-rs/toml#340.

Closing this out. If this is still a problem, feel free to recreate this issue in the new repo.

@epage epage closed this as completed Sep 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants