serde icon indicating copy to clipboard operation
serde copied to clipboard

[Suggest] Deserialize user-defined types including resource

Open cpunion opened this issue 1 year ago • 0 comments

I have asked a question on the Rust Discord forum How to deserialize a custom type containing Arc<File> from a generic parameter?, and I've completed a crate https://github.com/cpunion/axum-params. It works, but could be improved.

As described in the post above, user-defined types that include an Arc<File> field can't be deserialized. The workaround is to deserialize the path and hold File(s) in a container to prevent it from being dropped.

In the serde documentation https://serde.rs/data-model.html#types, serde supports many types, but the limitation seems to be that the types must be convertible or contain primitive types. Not all types need to be serialized to/deserialized from bytes. In my case, it just needs to serialize/deserialize to a DOM, where some types just need to be cloned to the target. I think this satisfies Serialize/Deserialize, just not SerializeToBytes/DeserializeFromBytes.

Would this use case be considered?

cpunion avatar Dec 28 '24 03:12 cpunion