Description
Looking into the rename feature I discovered that rustc does not gives an unreachable warning with serde rename collisions with enums
whereas it does on structs
as mentioned in #754
Would you still be open to a PR to make clashing renames an error? If so I'm happy to give it a go.
Example
use serde::{Deserialize};
#[derive(Deserialize)]
enum Message {
#[serde(rename = "Response")]
Request { id: String},
#[serde(rename = "Response")]
Response { id: String},
}
fn main() {
let json = "{\"Response\": {\"id\": \"...\"}}";
let parsed: Message = match serde_json::from_str(&json) {
Ok(contact) => contact,
Err(err) => {
println!("{:?}", err);
unimplemented!()
}
};
match parsed {
Message::Request { id } => println!("request {}", id),
Message::Response { id } => println!("response {}", id)
}
}
Output
request ...
with no compiler warnings
playgrounds link https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c6a787d51f1290af999a0e36b9a6d366
Metadata
Metadata
Assignees
Labels
No labels