Rust/Codegen: allow to "detach" property emission

By using the `rust.detach` pragma on a property, we make that property
not appear in the generated struct as a field, and provide instead
a `generated::Class::emit_property` function that can be used to emit
the corresponding TRAP entry independently.
This commit is contained in:
Paolo Tranquilli
2024-09-20 16:00:48 +02:00
parent d7aa5f1022
commit c74b6be136
4 changed files with 41 additions and 5 deletions

View File

@@ -59,6 +59,16 @@ pub struct {{name}} {
_unused: ()
}
{{/is_entry}}
{{#has_detached_fields}}
impl {{name}} {
{{#detached_fields}}
pub fn emit_{{singular_field_name}}(id: trap::Label<Self>, {{#is_repeated}}{{^is_unordered}}i: usize, {{/is_unordered}}{{/is_repeated}}value: {{base_type}}, out: &mut trap::Writer) {
out.add_tuple("{{table_name}}", vec![id.into(), {{#is_repeated}}{{^is_unordered}}i.into(), {{/is_unordered}}{{/is_repeated}}value.into()]);
}
{{/detached_fields}}
}
{{/has_detached_fields}}
impl trap::TrapClass for {{name}} {
fn class_name() -> &'static str { "{{name}}" }