Serialize separately from
Serialize creates a resolver for some object, then
Archive turns the value and that
resolver into an archived type. Having a separate
Serialize trait is necessary because although a
type may have only one archived representation, you may have options of what requirements to meet in
order to create one.
Serializetrait is parameterized over the serializer. The serializer is just a mutable object that helps the type serialize itself. The most basic types like
chardon't bound their serializer type because they can serialize themselves with any kind of serializer. More complex types like
Stringrequire a serializer that implements
Serializer, and even more complex types like
Vecrequire a serializer that additionally implement
Archive doesn't parameterize over the serializer used to make it. It shouldn't
matter what serializer a resolver was made with, only that it's made correctly.
rkyv provides serializers that provide all the functionality needed to serialize standard library types, as well as serializers that combine other serializers into a single object with all of the components' capabilities.
Many types require scratch space to serialize. This is some extra allocated space that they can use temporarily and return when they're done. For example,
Vecmight request scratch space to store the resolvers for its elements until it can serialize all of them. Requesting scratch space from the serializer allows scratch space to be reused many times, which reduces the number of slow memory allocations performed while serializing.