@@ -319,22 +319,40 @@ impl VersionedStruct {
319
319
crd_fn_calls : Vec < TokenStream > ,
320
320
enum_variants : Vec < ( Ident , String ) > ,
321
321
) -> TokenStream {
322
- let ident = & self . idents . kubernetes ;
322
+ let enum_ident = & self . idents . kubernetes ;
323
+ let enum_vis = & self . visibility ;
323
324
324
- let version_enum_definition = self . generate_kubernetes_version_enum ( enum_variants) ;
325
+ let mut enum_display_impl_matches = TokenStream :: new ( ) ;
326
+ let mut enum_variant_idents = TokenStream :: new ( ) ;
327
+
328
+ for ( enum_variant_ident, enum_variant_display) in enum_variants {
329
+ enum_variant_idents. extend ( quote ! { #enum_variant_ident, } ) ;
330
+ enum_display_impl_matches. extend ( quote ! {
331
+ #enum_ident:: #enum_variant_ident => f. write_str( #enum_variant_display) ,
332
+ } ) ;
333
+ }
325
334
326
335
quote ! {
327
336
#[ automatically_derived]
328
- pub struct #ident;
337
+ #enum_vis enum #enum_ident {
338
+ #enum_variant_idents
339
+ }
329
340
330
- #version_enum_definition
341
+ #[ automatically_derived]
342
+ impl :: std:: fmt:: Display for #enum_ident {
343
+ fn fmt( & self , f: & mut :: std:: fmt:: Formatter <' _>) -> :: std:: result:: Result <( ) , :: std:: fmt:: Error > {
344
+ match self {
345
+ #enum_display_impl_matches
346
+ }
347
+ }
348
+ }
331
349
332
350
#[ automatically_derived]
333
- impl #ident {
351
+ impl #enum_ident {
334
352
/// Generates a merged CRD which contains all versions defined using the
335
353
/// `#[versioned()]` macro.
336
354
pub fn merged_crd(
337
- stored_apiversion: Version
355
+ stored_apiversion: Self
338
356
) -> :: std:: result:: Result <:: k8s_openapi:: apiextensions_apiserver:: pkg:: apis:: apiextensions:: v1:: CustomResourceDefinition , :: kube:: core:: crd:: MergeError > {
339
357
:: kube:: core:: crd:: merge_crds( vec![ #( #crd_fn_calls) , * ] , & stored_apiversion. to_string( ) )
340
358
}
@@ -353,32 +371,4 @@ impl VersionedStruct {
353
371
<#path as :: kube:: CustomResourceExt >:: crd( )
354
372
}
355
373
}
356
-
357
- fn generate_kubernetes_version_enum ( & self , enum_variants : Vec < ( Ident , String ) > ) -> TokenStream {
358
- let mut enum_variant_matches = TokenStream :: new ( ) ;
359
- let mut enum_variant_idents = TokenStream :: new ( ) ;
360
-
361
- for ( enum_variant_ident, enum_variant_display) in enum_variants {
362
- enum_variant_idents. extend ( quote ! { #enum_variant_ident, } ) ;
363
- enum_variant_matches. extend ( quote ! {
364
- Version :: #enum_variant_ident => f. write_str( #enum_variant_display) ,
365
- } ) ;
366
- }
367
-
368
- quote ! {
369
- #[ automatically_derived]
370
- pub enum Version {
371
- #enum_variant_idents
372
- }
373
-
374
- #[ automatically_derived]
375
- impl :: std:: fmt:: Display for Version {
376
- fn fmt( & self , f: & mut :: std:: fmt:: Formatter <' _>) -> :: std:: result:: Result <( ) , :: std:: fmt:: Error > {
377
- match self {
378
- #enum_variant_matches
379
- }
380
- }
381
- }
382
- }
383
- }
384
374
}
0 commit comments