Is there a way for me to use #[derive] on a struct or enum from a library without editing the actual library's source code?

后端 未结 1 1306
后悔当初
后悔当初 2020-12-11 22:58

I am working on a Rust program that uses serde-json, and I really like the #[derive(Serialize, Deserialize)] macros that it gives for use with custom structs an

相关标签:
1条回答
  • Is there a way for me to use #[derive] on a struct or enum from a library without editing the actual library's source code?

    No, there is not.

    See also:

    • How do I implement a trait I don't own for a type I don't own?

    For the specific case of Serde, you can use "remote deriving", but you have to provide a duplicate definition of the type, essentially rewriting the original structure.

    Many crates provide a feature flag to enable optional functionality, so you may want to look to see if your crate has one for Serde. If it doesn't, you could submit such to the library.

    0 讨论(0)
提交回复
热议问题