{"action":"created","comment":{"url":"https://api.github.com/repos/serde-rs/serde/pulls/comments/125625937","pull_request_review_id":48027503,"id":125625937,"diff_hunk":"@@ -696,6 +696,262 @@ fn test_internally_tagged_enum() {\n }\n \n #[test]\n+fn test_internally_tagged_enum_renamed() {\n+    #[derive(Debug, PartialEq, Serialize, Deserialize)]\n+    struct Newtype(BTreeMap<String, String>);\n+\n+    #[derive(Debug, PartialEq, Serialize, Deserialize)]\n+    struct Struct {\n+        f: u8,\n+    }\n+\n+    #[derive(Debug, PartialEq, Serialize, Deserialize)]\n+    #[serde(tag = \"type\")]\n+    enum InternallyTagged {\n+        #[serde(rename=\"abc\")]\n+        A { a: u8 },\n+        #[serde(rename=\"true\", rename_as=\"bool\")]\n+        B { b: u8 },\n+        #[serde(rename=\"3\", rename_as=\"int\")]\n+        C,\n+        #[serde(rename=\"4\", rename_as=\"int\")]\n+        D(BTreeMap<String, String>),\n+        #[serde(rename=\"5\", rename_as=\"int\")]\n+        E(Newtype),\n+        #[serde(rename=\"6\", rename_as=\"int\")]\n+        F(Struct),\n+    }\n+\n+    assert_tokens(\n+        &InternallyTagged::A { a: 1 },\n+        &[\n+            Token::Struct { name: \"InternallyTagged\", len: 2 },\n+\n+            Token::Str(\"type\"),\n+            Token::Str(\"abc\"),\n+\n+            Token::Str(\"a\"),\n+            Token::U8(1),\n+\n+            Token::StructEnd,\n+        ],\n+    );\n+\n+    assert_tokens(\n+        &InternallyTagged::B { b: 1 },\n+        &[\n+            Token::Struct { name: \"InternallyTagged\", len: 2 },\n+\n+            Token::Str(\"type\"),\n+            Token::Bool(true),\n+\n+            Token::Str(\"b\"),\n+            Token::U8(1),\n+\n+            Token::StructEnd,\n+        ],\n+    );\n+\n+    assert_tokens(\n+        &InternallyTagged::C,\n+        &[\n+            Token::Struct { name: \"InternallyTagged\", len: 1 },\n+\n+            Token::Str(\"type\"),\n+            Token::U64(3),\n+\n+            Token::StructEnd,\n+        ],\n+    );\n+\n+    assert_tokens(\n+        &InternallyTagged::D(BTreeMap::new()),\n+        &[\n+            Token::Map { len: Some(1) },\n+\n+            Token::Str(\"type\"),\n+            Token::U64(4),\n+\n+            Token::MapEnd,\n+        ],\n+    );\n+\n+    assert_tokens(\n+        &InternallyTagged::E(Newtype(BTreeMap::new())),\n+        &[\n+            Token::Map { len: Some(1) },\n+\n+            Token::Str(\"type\"),\n+            Token::U64(5),\n+\n+            Token::MapEnd,\n+        ],\n+    );\n+\n+    assert_tokens(\n+        &InternallyTagged::F(Struct { f: 6 }),\n+        &[\n+            Token::Struct { name: \"Struct\", len: 2 },\n+\n+            Token::Str(\"type\"),\n+            Token::U64(6),\n+\n+            Token::Str(\"f\"),\n+            Token::U8(6),\n+\n+            Token::StructEnd,\n+        ],\n+    );\n+\n+    assert_de_tokens_error::<InternallyTagged>(\n+        &[\n+            Token::Map { len: Some(1) },\n+            Token::Str(\"type\"),\n+            Token::Bool(false)\n+        ],\n+        \"unknown variant `false`, expected one of `abc`, `true`, `3`, `4`, `5`, `6`\",\n+    );\n+\n+    assert_de_tokens_error::<InternallyTagged>(\n+        &[\n+            Token::Struct { name: \"Struct\", len: 2 },\n+            Token::Str(\"type\"),\n+            Token::U8(9),\n+        ],\n+        \"unknown variant `9`, expected one of `abc`, `true`, `3`, `4`, `5`, `6`\",\n+    );\n+}\n+\n+#[test]\n+fn test_adjacently_tagged_enum_renamed() {\n+    #[derive(Debug, PartialEq, Serialize, Deserialize)]\n+    struct Newtype(BTreeMap<String, String>);\n+\n+    #[derive(Debug, PartialEq, Serialize, Deserialize)]\n+    struct Struct {\n+        f: u8,\n+    }\n+\n+    #[derive(Debug, PartialEq, Serialize, Deserialize)]\n+    #[serde(tag = \"t\", content = \"c\")]\n+    enum AdjacentlyTagged {\n+        #[serde(rename=\"abc\")]\n+        A { a: u8 },\n+        #[serde(rename=\"true\", rename_as=\"bool\")]\n+        B { b: u8 },\n+        #[serde(rename=\"3\", rename_as=\"int\")]\n+        C,\n+        #[serde(rename=\"4\", rename_as=\"int\")]\n+        D(BTreeMap<String, String>),\n+        #[serde(rename=\"5\", rename_as=\"int\")]\n+        E(Newtype),\n+        #[serde(rename=\"6\", rename_as=\"int\")]\n+        F(Struct),\n+    }\n+\n+    assert_tokens(\n+        &AdjacentlyTagged::A { a: 1 },\n+        &[\n+            Token::Struct { name: \"AdjacentlyTagged\", len: 2 },\n+\n+            Token::Str(\"t\"),\n+            Token::Str(\"abc\"),\n+\n+            Token::Str(\"c\"),\n+            Token::Struct { name: \"abc\", len: 1 },\n+            Token::Str(\"a\"),\n+            Token::U8(1),\n+            Token::StructEnd,\n+\n+            Token::StructEnd,\n+        ],\n+    );\n+\n+    assert_tokens(\n+        &AdjacentlyTagged::B { b: 1 },\n+        &[\n+            Token::Struct { name: \"AdjacentlyTagged\", len: 2 },\n+\n+            Token::Str(\"t\"),\n+            Token::Bool(true),\n+\n+            Token::Str(\"c\"),\n+            // TODO: Is this the correct way to name the struct? stringify the rename?","path":"test_suite/tests/test_macros.rs","position":184,"original_position":184,"commit_id":"ea177de57152163c1a46664e9e325a7f4aaee189","original_commit_id":"ea177de57152163c1a46664e9e325a7f4aaee189","user":{"login":"Phaiax","id":1649278,"avatar_url":"https://avatars0.githubusercontent.com/u/1649278?v=3","gravatar_id":"","url":"https://api.github.com/users/Phaiax","html_url":"https://github.com/Phaiax","followers_url":"https://api.github.com/users/Phaiax/followers","following_url":"https://api.github.com/users/Phaiax/following{/other_user}","gists_url":"https://api.github.com/users/Phaiax/gists{/gist_id}","starred_url":"https://api.github.com/users/Phaiax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phaiax/subscriptions","organizations_url":"https://api.github.com/users/Phaiax/orgs","repos_url":"https://api.github.com/users/Phaiax/repos","events_url":"https://api.github.com/users/Phaiax/events{/privacy}","received_events_url":"https://api.github.com/users/Phaiax/received_events","type":"User","site_admin":false},"body":"that is the comment I referred to earlier in the review.","created_at":"2017-07-05T12:13:44Z","updated_at":"2017-07-05T12:14:06Z","html_url":"https://github.com/serde-rs/serde/pull/973#discussion_r125625937","pull_request_url":"https://api.github.com/repos/serde-rs/serde/pulls/973","_links":{"self":{"href":"https://api.github.com/repos/serde-rs/serde/pulls/comments/125625937"},"html":{"href":"https://github.com/serde-rs/serde/pull/973#discussion_r125625937"},"pull_request":{"href":"https://api.github.com/repos/serde-rs/serde/pulls/973"}}},"pull_request":{"url":"https://api.github.com/repos/serde-rs/serde/pulls/973","id":128482099,"html_url":"https://github.com/serde-rs/serde/pull/973","diff_url":"https://github.com/serde-rs/serde/pull/973.diff","patch_url":"https://github.com/serde-rs/serde/pull/973.patch","issue_url":"https://api.github.com/repos/serde-rs/serde/issues/973","number":973,"state":"open","locked":false,"title":"WIP: Allow #[serde(rename=str|bool|int)] for enum variants.","user":{"login":"Phaiax","id":1649278,"avatar_url":"https://avatars0.githubusercontent.com/u/1649278?v=3","gravatar_id":"","url":"https://api.github.com/users/Phaiax","html_url":"https://github.com/Phaiax","followers_url":"https://api.github.com/users/Phaiax/followers","following_url":"https://api.github.com/users/Phaiax/following{/other_user}","gists_url":"https://api.github.com/users/Phaiax/gists{/gist_id}","starred_url":"https://api.github.com/users/Phaiax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phaiax/subscriptions","organizations_url":"https://api.github.com/users/Phaiax/orgs","repos_url":"https://api.github.com/users/Phaiax/repos","events_url":"https://api.github.com/users/Phaiax/events{/privacy}","received_events_url":"https://api.github.com/users/Phaiax/received_events","type":"User","site_admin":false},"body":"(This commit contains untested code and a dirty hacks so that the rename=\"str\" still works)\r\n\r\n#745 Issue for this PR\r\n\r\nI got started and it was not too hard, serde derive is written very well. (I'm still confused by the deserializiation part, but I have not looked into it to much)\r\n\r\nSome questions:\r\n1. Non string literals are not stabilized yet. I think we should support a fallback with `#[serde(rename=\"1\", rename_as=\"int\")]`. This is necessary since serde supports old rustc versions anyway, so even with [stabilization](https://github.com/rust-lang/rust/issues/34981) this will not go away.\r\n    ```\r\n    error: non-string literals in attributes, or string literals in top-level positions, are experimental (see issue #34981)\r\n       --> tests/test_macros.rs:713:9\r\n        |\r\n    713 |         #[serde(rename=true)]\r\n        |         ^^^^^^^^^^^^^^^^^^^^^\r\n        |\r\n        = help: add #![feature(attr_literals)] to the crate attributes to enable\r\n    ```\r\n2. Currently I implemented a type `StrBoolInt`, but I had to define it twice, once in `serde_derive_internals` and once again in `serde_derive`, so that I can implement `ToTokens`.\r\n3. The second `StrBoolInt` is stuffed into `fragment.rs`. Should I use a new file or is that ok?\r\n3. I decided to only allow non-string renames for internally and adjacently tagged enums. Correct?\r\n4. As far as I understood it, `Serializers` have the choice to serialize either with the name of the variant or with the id. What happens if `rename=2` is stated for attribute with field number 1? Should I just replace the whole the `derserialize_u32` part as soon as an int-rename is encountered?\r\n5. What is that `[#serde(field_identifier/variant_identifier)]` setting? It is not mentioned in the docs.\r\n\r\nThx, Daniel","created_at":"2017-07-01T08:47:56Z","updated_at":"2017-07-05T12:14:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ca34c666c9ce0d2e7b76cdc157173c786a03547","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/serde-rs/serde/pulls/973/commits","review_comments_url":"https://api.github.com/repos/serde-rs/serde/pulls/973/comments","review_comment_url":"https://api.github.com/repos/serde-rs/serde/pulls/comments{/number}","comments_url":"https://api.github.com/repos/serde-rs/serde/issues/973/comments","statuses_url":"https://api.github.com/repos/serde-rs/serde/statuses/ea177de57152163c1a46664e9e325a7f4aaee189","head":{"label":"Phaiax:enum_tag_int","ref":"enum_tag_int","sha":"ea177de57152163c1a46664e9e325a7f4aaee189","user":{"login":"Phaiax","id":1649278,"avatar_url":"https://avatars0.githubusercontent.com/u/1649278?v=3","gravatar_id":"","url":"https://api.github.com/users/Phaiax","html_url":"https://github.com/Phaiax","followers_url":"https://api.github.com/users/Phaiax/followers","following_url":"https://api.github.com/users/Phaiax/following{/other_user}","gists_url":"https://api.github.com/users/Phaiax/gists{/gist_id}","starred_url":"https://api.github.com/users/Phaiax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phaiax/subscriptions","organizations_url":"https://api.github.com/users/Phaiax/orgs","repos_url":"https://api.github.com/users/Phaiax/repos","events_url":"https://api.github.com/users/Phaiax/events{/privacy}","received_events_url":"https://api.github.com/users/Phaiax/received_events","type":"User","site_admin":false},"repo":{"id":95900500,"name":"serde","full_name":"Phaiax/serde","owner":{"login":"Phaiax","id":1649278,"avatar_url":"https://avatars0.githubusercontent.com/u/1649278?v=3","gravatar_id":"","url":"https://api.github.com/users/Phaiax","html_url":"https://github.com/Phaiax","followers_url":"https://api.github.com/users/Phaiax/followers","following_url":"https://api.github.com/users/Phaiax/following{/other_user}","gists_url":"https://api.github.com/users/Phaiax/gists{/gist_id}","starred_url":"https://api.github.com/users/Phaiax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phaiax/subscriptions","organizations_url":"https://api.github.com/users/Phaiax/orgs","repos_url":"https://api.github.com/users/Phaiax/repos","events_url":"https://api.github.com/users/Phaiax/events{/privacy}","received_events_url":"https://api.github.com/users/Phaiax/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Phaiax/serde","description":"Serialization framework for Rust","fork":true,"url":"https://api.github.com/repos/Phaiax/serde","forks_url":"https://api.github.com/repos/Phaiax/serde/forks","keys_url":"https://api.github.com/repos/Phaiax/serde/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Phaiax/serde/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Phaiax/serde/teams","hooks_url":"https://api.github.com/repos/Phaiax/serde/hooks","issue_events_url":"https://api.github.com/repos/Phaiax/serde/issues/events{/number}","events_url":"https://api.github.com/repos/Phaiax/serde/events","assignees_url":"https://api.github.com/repos/Phaiax/serde/assignees{/user}","branches_url":"https://api.github.com/repos/Phaiax/serde/branches{/branch}","tags_url":"https://api.github.com/repos/Phaiax/serde/tags","blobs_url":"https://api.github.com/repos/Phaiax/serde/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Phaiax/serde/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Phaiax/serde/git/refs{/sha}","trees_url":"https://api.github.com/repos/Phaiax/serde/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Phaiax/serde/statuses/{sha}","languages_url":"https://api.github.com/repos/Phaiax/serde/languages","stargazers_url":"https://api.github.com/repos/Phaiax/serde/stargazers","contributors_url":"https://api.github.com/repos/Phaiax/serde/contributors","subscribers_url":"https://api.github.com/repos/Phaiax/serde/subscribers","subscription_url":"https://api.github.com/repos/Phaiax/serde/subscription","commits_url":"https://api.github.com/repos/Phaiax/serde/commits{/sha}","git_commits_url":"https://api.github.com/repos/Phaiax/serde/git/commits{/sha}","comments_url":"https://api.github.com/repos/Phaiax/serde/comments{/number}","issue_comment_url":"https://api.github.com/repos/Phaiax/serde/issues/comments{/number}","contents_url":"https://api.github.com/repos/Phaiax/serde/contents/{+path}","compare_url":"https://api.github.com/repos/Phaiax/serde/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Phaiax/serde/merges","archive_url":"https://api.github.com/repos/Phaiax/serde/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Phaiax/serde/downloads","issues_url":"https://api.github.com/repos/Phaiax/serde/issues{/number}","pulls_url":"https://api.github.com/repos/Phaiax/serde/pulls{/number}","milestones_url":"https://api.github.com/repos/Phaiax/serde/milestones{/number}","notifications_url":"https://api.github.com/repos/Phaiax/serde/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Phaiax/serde/labels{/name}","releases_url":"https://api.github.com/repos/Phaiax/serde/releases{/id}","deployments_url":"https://api.github.com/repos/Phaiax/serde/deployments","created_at":"2017-06-30T15:18:53Z","updated_at":"2017-06-30T15:18:55Z","pushed_at":"2017-07-04T14:33:19Z","git_url":"git://github.com/Phaiax/serde.git","ssh_url":"git@github.com:Phaiax/serde.git","clone_url":"https://github.com/Phaiax/serde.git","svn_url":"https://github.com/Phaiax/serde","homepage":"https://serde.rs/","size":4343,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"serde-rs:master","ref":"master","sha":"9ecb0839deda43ea430d873018b112c7faf90f15","user":{"login":"serde-rs","id":11965399,"avatar_url":"https://avatars0.githubusercontent.com/u/11965399?v=3","gravatar_id":"","url":"https://api.github.com/users/serde-rs","html_url":"https://github.com/serde-rs","followers_url":"https://api.github.com/users/serde-rs/followers","following_url":"https://api.github.com/users/serde-rs/following{/other_user}","gists_url":"https://api.github.com/users/serde-rs/gists{/gist_id}","starred_url":"https://api.github.com/users/serde-rs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serde-rs/subscriptions","organizations_url":"https://api.github.com/users/serde-rs/orgs","repos_url":"https://api.github.com/users/serde-rs/repos","events_url":"https://api.github.com/users/serde-rs/events{/privacy}","received_events_url":"https://api.github.com/users/serde-rs/received_events","type":"Organization","site_admin":false},"repo":{"id":14367737,"name":"serde","full_name":"serde-rs/serde","owner":{"login":"serde-rs","id":11965399,"avatar_url":"https://avatars0.githubusercontent.com/u/11965399?v=3","gravatar_id":"","url":"https://api.github.com/users/serde-rs","html_url":"https://github.com/serde-rs","followers_url":"https://api.github.com/users/serde-rs/followers","following_url":"https://api.github.com/users/serde-rs/following{/other_user}","gists_url":"https://api.github.com/users/serde-rs/gists{/gist_id}","starred_url":"https://api.github.com/users/serde-rs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serde-rs/subscriptions","organizations_url":"https://api.github.com/users/serde-rs/orgs","repos_url":"https://api.github.com/users/serde-rs/repos","events_url":"https://api.github.com/users/serde-rs/events{/privacy}","received_events_url":"https://api.github.com/users/serde-rs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/serde-rs/serde","description":"Serialization framework for Rust","fork":false,"url":"https://api.github.com/repos/serde-rs/serde","forks_url":"https://api.github.com/repos/serde-rs/serde/forks","keys_url":"https://api.github.com/repos/serde-rs/serde/keys{/key_id}","collaborators_url":"https://api.github.com/repos/serde-rs/serde/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/serde-rs/serde/teams","hooks_url":"https://api.github.com/repos/serde-rs/serde/hooks","issue_events_url":"https://api.github.com/repos/serde-rs/serde/issues/events{/number}","events_url":"https://api.github.com/repos/serde-rs/serde/events","assignees_url":"https://api.github.com/repos/serde-rs/serde/assignees{/user}","branches_url":"https://api.github.com/repos/serde-rs/serde/branches{/branch}","tags_url":"https://api.github.com/repos/serde-rs/serde/tags","blobs_url":"https://api.github.com/repos/serde-rs/serde/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/serde-rs/serde/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/serde-rs/serde/git/refs{/sha}","trees_url":"https://api.github.com/repos/serde-rs/serde/git/trees{/sha}","statuses_url":"https://api.github.com/repos/serde-rs/serde/statuses/{sha}","languages_url":"https://api.github.com/repos/serde-rs/serde/languages","stargazers_url":"https://api.github.com/repos/serde-rs/serde/stargazers","contributors_url":"https://api.github.com/repos/serde-rs/serde/contributors","subscribers_url":"https://api.github.com/repos/serde-rs/serde/subscribers","subscription_url":"https://api.github.com/repos/serde-rs/serde/subscription","commits_url":"https://api.github.com/repos/serde-rs/serde/commits{/sha}","git_commits_url":"https://api.github.com/repos/serde-rs/serde/git/commits{/sha}","comments_url":"https://api.github.com/repos/serde-rs/serde/comments{/number}","issue_comment_url":"https://api.github.com/repos/serde-rs/serde/issues/comments{/number}","contents_url":"https://api.github.com/repos/serde-rs/serde/contents/{+path}","compare_url":"https://api.github.com/repos/serde-rs/serde/compare/{base}...{head}","merges_url":"https://api.github.com/repos/serde-rs/serde/merges","archive_url":"https://api.github.com/repos/serde-rs/serde/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/serde-rs/serde/downloads","issues_url":"https://api.github.com/repos/serde-rs/serde/issues{/number}","pulls_url":"https://api.github.com/repos/serde-rs/serde/pulls{/number}","milestones_url":"https://api.github.com/repos/serde-rs/serde/milestones{/number}","notifications_url":"https://api.github.com/repos/serde-rs/serde/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/serde-rs/serde/labels{/name}","releases_url":"https://api.github.com/repos/serde-rs/serde/releases{/id}","deployments_url":"https://api.github.com/repos/serde-rs/serde/deployments","created_at":"2013-11-13T15:22:58Z","updated_at":"2017-07-04T19:43:54Z","pushed_at":"2017-07-04T14:33:20Z","git_url":"git://github.com/serde-rs/serde.git","ssh_url":"git@github.com:serde-rs/serde.git","clone_url":"https://github.com/serde-rs/serde.git","svn_url":"https://github.com/serde-rs/serde","homepage":"https://serde.rs/","size":4254,"stargazers_count":981,"watchers_count":981,"language":"Rust","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":132,"mirror_url":null,"open_issues_count":93,"forks":132,"open_issues":93,"watchers":981,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/serde-rs/serde/pulls/973"},"html":{"href":"https://github.com/serde-rs/serde/pull/973"},"issue":{"href":"https://api.github.com/repos/serde-rs/serde/issues/973"},"comments":{"href":"https://api.github.com/repos/serde-rs/serde/issues/973/comments"},"review_comments":{"href":"https://api.github.com/repos/serde-rs/serde/pulls/973/comments"},"review_comment":{"href":"https://api.github.com/repos/serde-rs/serde/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/serde-rs/serde/pulls/973/commits"},"statuses":{"href":"https://api.github.com/repos/serde-rs/serde/statuses/ea177de57152163c1a46664e9e325a7f4aaee189"}}}}
{"actor":{"display_login":"Phaiax"}}