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?

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:


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.

Leave a Comment