-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handle serde_as on enum variants #499
Change the serde_as macro to warn on serde_as attributes on enum variant fields. They are unsupported (in contrast to serde_derive), so showing an error is better and avoids confusion when migrating. Also update the main examples to include an enum.
- Loading branch information
Showing
6 changed files
with
102 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
serde_with_macros/tests/compile-fail/serde_as-enum-variant-499.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with_macros::serde_as; | ||
|
||
#[serde_as] | ||
#[derive(Serialize, Deserialize)] | ||
#[serde(tag = "messageType", content = "content")] | ||
/// The contents of a message combined with the `MessageType` | ||
pub enum MessageContentJsonStringEnum { | ||
/// A normal message | ||
Text(String), | ||
/// Fancy object message | ||
#[serde_as(as = "serde_with::json::JsonString")] | ||
Object(String), | ||
} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
serde_with_macros/tests/compile-fail/serde_as-enum-variant-499.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: serde_as attribute is not allowed on enum variants | ||
--> tests/compile-fail/serde_as-enum-variant-499.rs:12:5 | ||
| | ||
12 | #[serde_as(as = "serde_with::json::JsonString")] | ||
| ^ |