Skip to content

Adjacently tagged enums don't work in formats not supporting string values #2881

@inetic

Description

@inetic

I'm using the bencode format which doesn't differentiate between strings and bytes.

In particular I'm working with serde-bencode which currently has a test ser_de_flattened_adjacently_tagged_enum ignored due of this issue.

The test fails with the error InvalidType("Invalid Type: byte array (expected: string or map)") coming from serde/ContentDeserializer::deserialize_enum.

Before returning the error, the self.content variable contains Content::ByteBuf(b"Request") instead of a string.

Applying the below patch in that function seems to resolve the issue, but I'm not too familiar with the serde code so please let me know if you think this is or isn't an adequate solution (full diff here).

-                s @ Content::String(_) | s @ Content::Str(_) => (s, None),
+                s @ Content::String(_)
+               | s @ Content::Str(_)
+               | s @ Content::ByteBuf(_)
+               | s @ Content::Bytes(_) => (s, None),

For posterity, adjacently tagged enums worked OK in serde-bencode with serde v1.0.180 but broke with >=v1.0.181.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions