Derive macros are created to derive a trait on structs. Lets create a trait called Serialize and Deserialize that supports two functions -

use std::fmt::Error;

trait Serialize {
	fn serialize(&self) -> Vec<u8>;
}

trait Deserialize: Sized {
	fn deserialize(base: &[u8]) -> Result<Self, Error>;
}

We need to create two Custom derive macros for these traits. Both should be able to pack a struct into bytes and vice versa.

<aside> 💡

What is the problem in this approach? Does it work for any struct? or just for this specific struct?

How can we make it more generic

</aside>