0

Rust provides a Serialize and Deserialize macro which are applied by decorating the struct you're defining with #[derive(Serialize)] and #[derive(Deserialize)]. How do I apply these macros if I'm not defining the struct? Like let's say I have,

use foo::Bar;

And Bar is a struct. How can I make it such that the Bar struct can be serialized and deserialized from within Actix? You can't apply the Serialize macro to use statements or you'll get,

error[E0774]: `derive` may only be applied to structs, enums and unions
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • Do these help? https://stackoverflow.com/questions/65279642/how-can-i-implement-serde-for-a-type-that-i-dont-own-and-have-it-support-compou https://stackoverflow.com/questions/57982831/can-one-implement-derive-serialize-on-an-enum-without-deriveserialize – kmdreko Mar 04 '21 at 03:33
  • The docs have a section called ["Derive for remote crate"](https://serde.rs/remote-derive.html) – Jmb Mar 04 '21 at 07:41

0 Answers0