11pub mod attrs;
22pub mod parser;
33pub mod schema_check;
4- pub mod string_lit ;
4+ pub mod struct_expr ;
55pub mod writer;
66
77use anyhow:: { Result , bail} ;
@@ -179,7 +179,9 @@ fn print_summary(files_scanned: usize, files_skipped: usize, instances_generated
179179 println ! ( " Files skipped: {files_skipped}" ) ;
180180 println ! ( " Instances generated: {instances_generated}" ) ;
181181 if instances_generated == 0 {
182- println ! ( "\n No instances found. Annotate consts with `#[gts_well_known_instance(...)]`." ) ;
182+ println ! (
183+ "\n No instances found. Annotate fn items with `#[gts_well_known_instance(...)]`."
184+ ) ;
183185 }
184186}
185187
@@ -193,16 +195,18 @@ mod tests {
193195 fs:: write ( dir. join ( name) , content) . unwrap ( ) ;
194196 }
195197
196- fn valid_src ( id : & str , json_body : & str ) -> String {
198+ fn valid_src ( id : & str , struct_body : & str ) -> String {
197199 format ! (
198200 concat!(
199201 "#[gts_well_known_instance(\n " ,
200202 " dir_path = \" instances\" ,\n " ,
201203 " id = \" {}\" \n " ,
202204 ")]\n " ,
203- "pub const FOO: &str = {};\n "
205+ "fn get_instance_item_v1() -> MyStruct {{\n " ,
206+ " {}\n " ,
207+ "}}\n "
204208 ) ,
205- id, json_body
209+ id, struct_body
206210 )
207211 }
208212
@@ -216,7 +220,7 @@ mod tests {
216220 "module.rs" ,
217221 & valid_src (
218222 "gts.x.core.events.topic.v1~x.commerce._.orders.v1.0" ,
219- r#""{\" name\": \ "orders\", \" partitions\" : 16}" "# ,
223+ r#"MyStruct { name: String::from( "orders"), partitions: 16 } "# ,
220224 ) ,
221225 ) ;
222226
@@ -256,12 +260,16 @@ mod tests {
256260 " dir_path = \" instances\" ,\n " ,
257261 " id = \" gts.x.core.events.topic.v1~x.commerce._.orders.v1.0\" \n " ,
258262 ")]\n " ,
259- "const A: &str = \" {\\ \" name\\ \" : \\ \" a\\ \" }\" ;\n " ,
263+ "fn get_instance_orders_v1() -> MyStruct {\n " ,
264+ " MyStruct { name: String::from(\" a\" ) }\n " ,
265+ "}\n " ,
260266 "#[gts_well_known_instance(\n " ,
261267 " dir_path = \" instances\" ,\n " ,
262268 " id = \" gts.x.core.events.topic.v1~x.commerce._.orders.v1.0\" \n " ,
263269 ")]\n " ,
264- "const B: &str = \" {\\ \" name\\ \" : \\ \" b\\ \" }\" ;\n "
270+ "fn get_instance_orders2_v1() -> MyStruct {\n " ,
271+ " MyStruct { name: String::from(\" b\" ) }\n " ,
272+ "}\n "
265273 ) ;
266274 write_src ( & root, "dup.rs" , dup_src) ;
267275
@@ -295,7 +303,9 @@ mod tests {
295303 " dir_path = \" instances\" ,\n " ,
296304 " id = \" bad-no-tilde\" \n " ,
297305 ")]\n " ,
298- "const X: &str = \" {}\" ;\n "
306+ "fn get_instance_bad_v1() -> MyStruct {\n " ,
307+ " MyStruct { name: String::from(\" x\" ) }\n " ,
308+ "}\n "
299309 ) ,
300310 ) ;
301311
0 commit comments