Integration with `serde` rename?
Hi! I'm just starting to look at this to replace my own hand rolled version, and this looks great. I wonder, have you considered allowing the use of #[serde(rename=...)] alongside using your own rename attribute?
Thanks!
for a bit more information, I have a bunch of Events, with a discriminator that is used to query in a bunch of places. I've a hand-crafted EventType with a ToSql and FromSql implementation.
This means that client code can use the strongly types EventType to declare the Events they are interested in, and the DB layer can translate that safely to/from a SQL query. I also have serde(rename="..") on the Event and EventType itself, kept in sync by hope, luck, and best wishes.
It would be awesome therefore, if I could do something like:
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename="camelCase")]
pub enum Event {
#[serde(rename="LoggedIn"))
Login(LoginDetail)
Logout(LogoutDetail)
}
and kinded could somehow generate:
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename="camelCase")]
pub enum EventKind {
#[serde(rename="LoggedIn"))
Login
Logout
}
and I could then write my own To/From string:
impl Display for EventKind {
fn display(&self, ....) {
// serialize self to json and return
}
}
impl From<&str> for EventKind {
fn from(s: &str) -> Self {
// deserialize self to json and return
}
}
10 bonus points if the kinded magic could actually use knowledge of the serde attributes to generate a more efficient impl from the literal strings...
Does that make sense, and is that possible?
(apologies for butchering Rust - I'm away from my usual laptop)