@@ -237,6 +237,21 @@ fn module_name(camel_case : &str) -> String {
237
237
name
238
238
}
239
239
240
+ const NAME_ANNOTATION_ID : u64 = 0xc2fe4c6d100166d0 ;
241
+
242
+ fn get_field_name ( field : schema_capnp:: field:: Reader ) -> capnp:: Result < & str > {
243
+ for annotation in field. get_annotations ( ) ?. iter ( ) {
244
+ if annotation. get_id ( ) == NAME_ANNOTATION_ID {
245
+ if let schema_capnp:: value:: Text ( t) = annotation. get_value ( ) ?. which ( ) ? {
246
+ return t;
247
+ } else {
248
+ return Err ( capnp:: Error :: failed ( format ! ( "expected rust.name annotation value to be of type Text" ) ) ) ;
249
+ }
250
+ }
251
+ }
252
+ field. get_name ( )
253
+ }
254
+
240
255
fn populate_scope_map ( node_map : & collections:: hash_map:: HashMap < u64 , schema_capnp:: node:: Reader > ,
241
256
scope_map : & mut collections:: hash_map:: HashMap < u64 , Vec < String > > ,
242
257
scope_names : Vec < String > ,
@@ -274,7 +289,7 @@ fn populate_scope_map(node_map: &collections::hash_map::HashMap<u64, schema_capn
274
289
for field in fields. iter ( ) {
275
290
match field. which ( ) {
276
291
Ok ( schema_capnp:: field:: Group ( group) ) => {
277
- let name = module_name ( field . get_name ( ) ?) ;
292
+ let name = module_name ( get_field_name ( field ) ?) ;
278
293
let mut scope_names = scope_names. clone ( ) ;
279
294
scope_names. push ( name) ;
280
295
populate_scope_map ( node_map, scope_map, scope_names, group. get_type_id ( ) ) ?;
@@ -371,7 +386,7 @@ pub fn getter_text(gen: &GeneratorContext,
371
386
let typ = raw_type. type_string ( gen, module) ?;
372
387
let default_value = reg_field. get_default_value ( ) ?;
373
388
let default = default_value. which ( ) ?;
374
- let default_name = format ! ( "DEFAULT_{}" , snake_to_upper_case( & camel_to_snake_case( field . get_name ( ) ?) ) ) ;
389
+ let default_name = format ! ( "DEFAULT_{}" , snake_to_upper_case( & camel_to_snake_case( get_field_name ( * field ) ?) ) ) ;
375
390
376
391
let mut result_type = match raw_type. which ( ) ? {
377
392
type_:: Enum ( _) => format ! ( "::std::result::Result<{},::capnp::NotInSchema>" , typ) ,
@@ -778,7 +793,7 @@ fn generate_union(gen: &GeneratorContext,
778
793
779
794
let dvalue = field. get_discriminant_value ( ) as usize ;
780
795
781
- let field_name = field . get_name ( ) ?;
796
+ let field_name = get_field_name ( * field ) ?;
782
797
let enumerant_name = capitalize_first_letter ( field_name) ;
783
798
784
799
let ( ty, get, maybe_default_decl) = getter_text ( gen, field, is_reader, false ) ?;
@@ -907,7 +922,7 @@ fn generate_pipeline_getter(gen: &GeneratorContext,
907
922
field : schema_capnp:: field:: Reader ) -> :: capnp:: Result < FormattedText > {
908
923
use crate :: schema_capnp:: { field, type_} ;
909
924
910
- let name = field . get_name ( ) ?;
925
+ let name = get_field_name ( field ) ?;
911
926
912
927
match field. which ( ) ? {
913
928
field:: Group ( group) => {
@@ -1094,7 +1109,7 @@ fn generate_node(gen: &GeneratorContext,
1094
1109
1095
1110
let fields = struct_reader. get_fields ( ) ?;
1096
1111
for field in fields. iter ( ) {
1097
- let name = field . get_name ( ) ?;
1112
+ let name = get_field_name ( field ) ?;
1098
1113
let styled_name = camel_to_snake_case ( name) ;
1099
1114
1100
1115
let discriminant_value = field. get_discriminant_value ( ) ;
@@ -1160,7 +1175,7 @@ fn generate_node(gen: &GeneratorContext,
1160
1175
reexports. push_str ( "pub use self::Which::{" ) ;
1161
1176
let mut whichs = Vec :: new ( ) ;
1162
1177
for f in union_fields. iter ( ) {
1163
- whichs. push ( capitalize_first_letter ( f . get_name ( ) ?) ) ;
1178
+ whichs. push ( capitalize_first_letter ( get_field_name ( * f ) ?) ) ;
1164
1179
}
1165
1180
reexports. push_str ( & whichs. join ( "," ) ) ;
1166
1181
reexports. push_str ( "};" ) ;
0 commit comments