2021年3月3日星期三

How can you use the Serialization and Deserialization macros on things you don't define?

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  
https://stackoverflow.com/questions/66467930/how-can-you-use-the-serialization-and-deserialization-macros-on-things-you-dont March 04, 2021 at 10:57AM

没有评论:

发表评论