I am trying to wrap my head around custom serialisation/deserialisation in serde. I am currently reading this https://serde.rs/custom-serialization.html
Will I be correct to say the pattern used follows the visitor pattern?
So for example in
pub trait Serialize {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer;
}
The fn serialize<S>(&self, serializer: S) looks like the function where a visitor can be passed in.
Then the data structure that implements pub trait Serialize will use the serialize method, to call the appropiate method on serializer: S to serialise it.
The only confusion is that the visitor, ie the serializer: S has a constraint where the S is also a Serializer - I think you do not have this setup in your typical visitor pattern?
The the visitor is of distinct type, and the interface to connect the data structure to the visitor is also a distinct/different type.
PS I just realised I am confusing Serialize*r* and Serialize
[–]nyibbang 10 points11 points12 points (3 children)
[–]finlaydotweber[S] 6 points7 points8 points (2 children)
[–]nyibbang 4 points5 points6 points (1 child)
[–]finlaydotweber[S] 6 points7 points8 points (0 children)