I am new to rust and have been trying to deep dive into it. I came across a crate serde for serialization and deserialization of practically any type. I have been exploring ways to implement a way to serialize a specific struct to Vec<u8> and reconstruct it from the bytes vector in an efficient manner but cannot find anything concrete. Can anybody point me in the right direction?
P.S. I am not trying to rewrite serde myself, just been exploring what should I do to serialize one given struct.
serde is somewhat of the glue between your data structure (i.e. your types) that know how to serialise and deserialise themselves (by implementing serde::ser::Serialize and/or serde::de::Deserialize) and an actual (de-)serializer implementation that understands how to (de-)serialise certain structures like maps, numbers, structs, etc. for a certain data format (by implementing serde::ser::Serializer and/or serde::de::Deserializer).
You are looking for a data format implementation. Above I linked a listing with crates that implement a data format. While there are more efficient formats than JSON (check out the list), if all you need to do is get a byte vector from an object, you can call serde_json::to_vec on an instance of a type that implements Serialize.
Thanks, this is exactly what I needed. As I said this is not for practical implementations but me trying to understand how to go about serialization/deserialization on my own.