rust-typescript-type-def icon indicating copy to clipboard operation
rust-typescript-type-def copied to clipboard

Feature for serde_repr

Open Skippeh opened this issue 2 years ago • 2 comments

Using serde_repr for (de)serializing C style enums currently doesn't work. The generated enums are string unions.

Is it possible to add a feature for serde_repr so it (de)serializes the enums as numbers?

Skippeh avatar Jul 13 '23 13:07 Skippeh

Hmm, I'm not quite sure how I would even go about doing this. The way this library works is that when you use the TypeDef derive macro, it assumes you're using the standard Serialize/Deserialize derive macros on the struct as well, and looks for #[serde(...)] attributes in the struct to guide the format of the serialization. I'm not sure how I would even detect if you're using Serialize_repr/Deserialize_repr in my macro; it might not be possible. I might have to mimic serde's pattern and provide a distinct TypeDef_repr macro which similarly assumes that you're using Serialize_repr/Deserialize_repr on the type.

dbeckwith avatar Jul 22 '23 13:07 dbeckwith

I worked around the issue by using vectors in the api instead, so i don't personally need it anymore. Still sounds like it would be a good thing to have though if you feel like making it.

Skippeh avatar Jul 22 '23 14:07 Skippeh