@@ -21,7 +21,7 @@ mod r#enum;
21
21
mod r#struct;
22
22
23
23
/// Contains common container data shared between structs and enums.
24
- pub ( crate ) struct CommonContainerData {
24
+ pub struct CommonContainerData {
25
25
/// Original attributes placed on the container, like `#[derive()]` or `#[cfg()]`.
26
26
pub ( crate ) original_attributes : Vec < Attribute > ,
27
27
@@ -37,7 +37,7 @@ pub(crate) struct CommonContainerData {
37
37
/// Abstracting away with kind of container is generated makes it possible to create a list of
38
38
/// containers when the macro is used on modules. This enum provides functions to generate code
39
39
/// which then internally call the appropriate function based on the variant.
40
- pub ( crate ) enum Container {
40
+ pub enum Container {
41
41
Struct ( Struct ) ,
42
42
Enum ( Enum ) ,
43
43
}
@@ -51,16 +51,37 @@ impl Container {
51
51
}
52
52
}
53
53
54
- /// Generates the container `From<Version> for NextVersion` implementation.
55
- pub ( crate ) fn generate_from_impl (
54
+ /// Generates the `From<Version> for NextVersion` implementation for the container .
55
+ pub fn generate_upgrade_from_impl (
56
56
& self ,
57
57
version : & VersionDefinition ,
58
58
next_version : Option < & VersionDefinition > ,
59
59
add_attributes : bool ,
60
60
) -> Option < TokenStream > {
61
61
match self {
62
- Container :: Struct ( s) => s. generate_from_impl ( version, next_version, add_attributes) ,
63
- Container :: Enum ( e) => e. generate_from_impl ( version, next_version, add_attributes) ,
62
+ Container :: Struct ( s) => {
63
+ s. generate_upgrade_from_impl ( version, next_version, add_attributes)
64
+ }
65
+ Container :: Enum ( e) => {
66
+ e. generate_upgrade_from_impl ( version, next_version, add_attributes)
67
+ }
68
+ }
69
+ }
70
+
71
+ /// Generates the `From<NextVersion> for Version` implementation for the container.
72
+ pub fn generate_downgrade_from_impl (
73
+ & self ,
74
+ version : & VersionDefinition ,
75
+ next_version : Option < & VersionDefinition > ,
76
+ add_attributes : bool ,
77
+ ) -> Option < TokenStream > {
78
+ match self {
79
+ Container :: Struct ( s) => {
80
+ s. generate_downgrade_from_impl ( version, next_version, add_attributes)
81
+ }
82
+ Container :: Enum ( e) => {
83
+ e. generate_downgrade_from_impl ( version, next_version, add_attributes)
84
+ }
64
85
}
65
86
}
66
87
@@ -180,9 +201,17 @@ impl StandaloneContainer {
180
201
181
202
// NOTE (@Techassi): Using '.copied()' here does not copy or clone the data, but instead
182
203
// removes one level of indirection of the double reference '&&'.
183
- let from_impl =
204
+ let next_version = versions. peek ( ) . copied ( ) ;
205
+
206
+ // Generate the From impl for upgrading the CRD.
207
+ let upgrade_from_impl =
208
+ self . container
209
+ . generate_upgrade_from_impl ( version, next_version, false ) ;
210
+
211
+ // Generate the From impl for downgrading the CRD.
212
+ let downgrade_from_impl =
184
213
self . container
185
- . generate_from_impl ( version, versions . peek ( ) . copied ( ) , false ) ;
214
+ . generate_downgrade_from_impl ( version, next_version , false ) ;
186
215
187
216
// Add the #[deprecated] attribute when the version is marked as deprecated.
188
217
let deprecated_attribute = version
@@ -210,7 +239,8 @@ impl StandaloneContainer {
210
239
#container_definition
211
240
}
212
241
213
- #from_impl
242
+ #upgrade_from_impl
243
+ #downgrade_from_impl
214
244
} ) ;
215
245
}
216
246
@@ -231,13 +261,13 @@ impl StandaloneContainer {
231
261
pub ( crate ) struct ContainerIdents {
232
262
/// The ident used in the context of Kubernetes specific code. This ident
233
263
/// removes the 'Spec' suffix present in the definition container.
234
- pub ( crate ) kubernetes : IdentString ,
264
+ pub kubernetes : IdentString ,
235
265
236
266
/// The original ident, or name, of the versioned container.
237
- pub ( crate ) original : IdentString ,
267
+ pub original : IdentString ,
238
268
239
269
/// The ident used in the [`From`] impl.
240
- pub ( crate ) from : IdentString ,
270
+ pub from : IdentString ,
241
271
}
242
272
243
273
impl ContainerIdents {
@@ -261,32 +291,32 @@ impl ContainerIdents {
261
291
}
262
292
263
293
#[ derive( Debug ) ]
264
- pub ( crate ) struct ContainerOptions {
265
- pub ( crate ) kubernetes_options : Option < KubernetesOptions > ,
266
- pub ( crate ) skip_from : bool ,
294
+ pub struct ContainerOptions {
295
+ pub kubernetes_options : Option < KubernetesOptions > ,
296
+ pub skip_from : bool ,
267
297
}
268
298
269
299
#[ derive( Debug ) ]
270
- pub ( crate ) struct KubernetesOptions {
271
- pub ( crate ) group : String ,
272
- pub ( crate ) kind : Option < String > ,
273
- pub ( crate ) singular : Option < String > ,
274
- pub ( crate ) plural : Option < String > ,
275
- pub ( crate ) namespaced : bool ,
300
+ pub struct KubernetesOptions {
301
+ pub group : String ,
302
+ pub kind : Option < String > ,
303
+ pub singular : Option < String > ,
304
+ pub plural : Option < String > ,
305
+ pub namespaced : bool ,
276
306
// root
277
- pub ( crate ) crates : KubernetesCrateOptions ,
278
- pub ( crate ) status : Option < Path > ,
307
+ pub crates : KubernetesCrateOptions ,
308
+ pub status : Option < Path > ,
279
309
// derive
280
310
// schema
281
311
// scale
282
312
// printcolumn
283
- pub ( crate ) shortnames : Vec < String > ,
313
+ pub shortnames : Vec < String > ,
284
314
// category
285
315
// selectable
286
316
// doc
287
317
// annotation
288
318
// label
289
- pub ( crate ) skip_merged_crd : bool ,
319
+ pub skip_merged_crd : bool ,
290
320
}
291
321
292
322
impl From < KubernetesArguments > for KubernetesOptions {
@@ -308,12 +338,12 @@ impl From<KubernetesArguments> for KubernetesOptions {
308
338
}
309
339
310
340
#[ derive( Debug ) ]
311
- pub ( crate ) struct KubernetesCrateOptions {
312
- pub ( crate ) kube_core : Override < Path > ,
313
- pub ( crate ) k8s_openapi : Override < Path > ,
314
- pub ( crate ) schemars : Override < Path > ,
315
- pub ( crate ) serde : Override < Path > ,
316
- pub ( crate ) serde_json : Override < Path > ,
341
+ pub struct KubernetesCrateOptions {
342
+ pub kube_core : Override < Path > ,
343
+ pub k8s_openapi : Override < Path > ,
344
+ pub schemars : Override < Path > ,
345
+ pub serde : Override < Path > ,
346
+ pub serde_json : Override < Path > ,
317
347
}
318
348
319
349
impl Default for KubernetesCrateOptions {
@@ -396,7 +426,7 @@ impl ToTokens for KubernetesCrateOptions {
396
426
397
427
/// Wraps a value to indicate whether it is original or has been overridden.
398
428
#[ derive( Debug ) ]
399
- pub ( crate ) enum Override < T > {
429
+ pub enum Override < T > {
400
430
Default ( T ) ,
401
431
Overridden ( T ) ,
402
432
}
0 commit comments