Skip to content

DataBake: split serialized form from runtime form #2452

Open
@sffc

Description

@sffc

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
  }
}

CC @Manishearth @robertbastian

Metadata

Metadata

Labels

C-zerovecComponent: Yoke, ZeroVec, DataBakediscussDiscuss at a future ICU4X-SC meetingdiscuss-triagedThe stakeholders for this issue have been identified and it can be discussed out-of-band

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions