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

Vecs containing Option types are removed from output #603

Closed
evie-calico opened this issue Sep 8, 2023 · 2 comments · Fixed by #604
Closed

Vecs containing Option types are removed from output #603

evie-calico opened this issue Sep 8, 2023 · 2 comments · Fixed by #604
Labels
A-serde Area: Serde integration C-bug Category: Things not working as expected

Comments

@evie-calico
Copy link

If a vector contains an option type, and any of its entries are None, the vector is completely removed from the output. I believe this is because toml tries not to output anything for None values, but this chokes when trying to insert a gap with nothing in it.

If you create an enum with the same structure as Option, toml uses a different format that correctly handles "gaps" (shown in the below example); I believe this should be used for vectors of options.

Example on Rust Playground

@evie-calico
Copy link
Author

evie-calico commented Sep 8, 2023

The issue seems to be here

The ? bubbles all errors up, including UnsupportedNone, despite it having a special meaning. This causes the entire array to be removed. At the very least, UnsupportedNone should be transformed into another error:

let value = value.serialize(super::ValueSerializer {}).map_err(|e| {
    if let Error::UnsupportedNone = e {
        Error::UnsupportedType(Some("None is unsupported in vectors"))
    } else {
        e
    }
})?;

But supporting None in Vectors seems worth it :)

@epage
Copy link
Member

epage commented Sep 8, 2023

There are two different ways to look at this bug

The first is that we should be skipping None values in arrays like we do with maps.

The other is that we should more generally error.

I lean towards erroring because gaps may be significant and we wouldn't be able to represent that while having a table without a value can be represented (I misremembered the code).

If you create an enum with the same structure as Option, toml uses a different format that correctly handles "gaps" (shown in the below example); I believe this should be used for vectors of options.

In the enum case, there is a meaningful way of defining "gaps" based on the definition of your enum. With options, there isn't any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-serde Area: Serde integration C-bug Category: Things not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants