@@ -127,16 +127,18 @@ pub(crate) struct Struct {
127
127
/// should generate code, is decided by the currently generated version.
128
128
pub fields : Vec < VersionedField > ,
129
129
130
- pub generics : Generics ,
131
-
132
130
/// Common container data which is shared between structs and enums.
133
131
pub common : CommonContainerData ,
132
+
133
+ /// Generic types of the struct
134
+ pub generics : Generics ,
134
135
}
135
136
136
137
// Common token generation
137
138
impl Struct {
138
139
/// Generates code for the struct definition.
139
140
pub ( crate ) fn generate_definition ( & self , version : & VersionDefinition ) -> TokenStream {
141
+ let ( _, type_generics, where_clause) = self . generics . split_for_impl ( ) ;
140
142
let original_attributes = & self . common . original_attributes ;
141
143
let ident = & self . common . idents . original ;
142
144
let version_docs = & version. docs ;
@@ -153,7 +155,7 @@ impl Struct {
153
155
#( #[ doc = #version_docs] ) *
154
156
#( #original_attributes) *
155
157
#kube_attribute
156
- pub struct #ident {
158
+ pub struct #ident #type_generics #where_clause {
157
159
#fields
158
160
}
159
161
}
@@ -172,6 +174,12 @@ impl Struct {
172
174
173
175
match next_version {
174
176
Some ( next_version) => {
177
+ // TODO (@Techassi): Support generic types which have been removed in newer versions,
178
+ // but need to exist for older versions How do we represent that? Because the
179
+ // defined struct always represents the latest version. I guess we could generally
180
+ // advise against using generic types, but if you have to, avoid removing it in
181
+ // later versions.
182
+ let ( impl_generics, type_generics, where_clause) = self . generics . split_for_impl ( ) ;
175
183
let struct_ident = & self . common . idents . original ;
176
184
let from_struct_ident = & self . common . idents . from ;
177
185
@@ -198,8 +206,10 @@ impl Struct {
198
206
Some ( quote ! {
199
207
#automatically_derived
200
208
#allow_attribute
201
- impl :: std:: convert:: From <#from_module_ident:: #struct_ident> for #for_module_ident:: #struct_ident {
202
- fn from( #from_struct_ident: #from_module_ident:: #struct_ident) -> Self {
209
+ impl #impl_generics :: std:: convert:: From <#from_module_ident:: #struct_ident #type_generics> for #for_module_ident:: #struct_ident #type_generics
210
+ #where_clause
211
+ {
212
+ fn from( #from_struct_ident: #from_module_ident:: #struct_ident #type_generics) -> Self {
203
213
Self {
204
214
#fields
205
215
}
0 commit comments