Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Add support for more tokens served as enum variant identifiers #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Aug 12, 2023

This includes borrowed and owned variants of strings / bytes and all supported unsigned integers. Now the following tokens can be used as variant identifiers which is all supported by visitor implementations derived by serde_derive:

  • Token::BorrowedStr
  • Token::String
  • Token::BorrowedBytes
  • Token::ByteBuf
  • Token::U8
  • Token::U16
  • Token::U64

This is needed for the my PR to serde which expands test suite by this test:

#[derive(Debug, PartialEq, Serialize, Deserialize)]
enum Enum {
    Tuple(u8, u8),
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "tag")]
enum InternallyTagged {
    StructEnum { enum_: Enum },
}
//...
        let value = InternallyTagged::StructEnum {
            enum_: Enum::Tuple(4, 2),
        };
        assert_de_tokens(
            &value,
            &[
                Token::Struct {
                    name: "InternallyTagged",
                    len: 2,
                },
                Token::BorrowedStr("tag"),
                Token::BorrowedStr("StructEnum"),
                Token::BorrowedStr("enum_"),
                Token::Enum { name: "Enum" },
                Token::BorrowedStr("Tuple"), //<<< Impossible due to lack of support of BorrowedStr
                Token::Seq { len: Some(2) },
                Token::U8(4),
                Token::U8(2),
                Token::SeqEnd,
                Token::StructEnd,
            ],
        );

@Mingun Mingun force-pushed the borrowed-variant-identifiers branch 2 times, most recently from ed7e08b to a6a7116 Compare August 12, 2023 09:59
Mingun added a commit to Mingun/serde that referenced this pull request Aug 12, 2023
…internally tagged enum

failures (3) - until serde-deprecated/test#31 is merged:
    struct_enum::newtype
    struct_enum::struct_
    struct_enum::tuple
Mingun added a commit to Mingun/serde that referenced this pull request Aug 12, 2023
@Mingun
Copy link
Contributor Author

Mingun commented Aug 12, 2023

Failed check is due to network problems on runner.

Mingun added a commit to Mingun/serde that referenced this pull request Aug 5, 2024
…internally tagged enum

failures (3) - until serde-deprecated/test#31 is merged:
    struct_enum::newtype
    struct_enum::struct_
    struct_enum::tuple
Mingun added a commit to Mingun/serde that referenced this pull request Aug 5, 2024
This includes borrowed and owned variants of strings / bytes and all supported unsigned integers
@Mingun Mingun force-pushed the borrowed-variant-identifiers branch from a6a7116 to 39b260b Compare August 6, 2024 19:25
@Mingun
Copy link
Contributor Author

Mingun commented Aug 11, 2024

Could this PR take attention? It is needed to improve test coverage in serde. @dtolnay, @oli-obk.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant