Open
Description
A general DataBake feature that would solve several problems, including #2417, would be a way to specify a different data struct as the serialized form of the main data struct, with functions to convert between them.
For example, you might write
#[databake(path = foo)]
#[databake::serialize_as(path = foo::FooFields, from = from_fields, to = to_fields)]
pub struct Foo<'data> {
// private fields (NOT processed by the proc macro)
}
#[databake(path = foo)]
pub struct FooFields {
// public fields (processed by the proc macro)
}
impl<'data> Foo<'data> {
pub const fn from_fields(fields: &'data FooFields) -> Self {
// a cheap const constructor
}
pub fn to_fields(&self) -> FooFields {
// invoked during serialization only
}
}