Types
POD types
Since all types in the database are POD types, we must often provide mappings between outside types and the types actually stored in the database.
A common case is mapping infallible types to and from bitflags
and/or their raw integer representation.
For example, the OutputFlag
type or bool
types.
As types like enum
s, bool
s and char
s cannot be casted from an integer infallibly,
bytemuck::Pod
cannot be implemented on it safely. Thus, we store some infallible version
of it inside the database with a custom type and map them when fetching the data.
Lean types
Another reason why database crates define their own types is to cut any unneeded data from the type.
Many of the types used in normal operation (e.g. cuprate_types::VerifiedBlockInformation
) contain lots of extra pre-processed data for convenience.
This would be a waste to store in the database, so in this example, the much leaner
"raw" BlockInfo
type is stored.