@@ -478,11 +478,16 @@ mod utils;
478
478
/// #[versioned(changed(
479
479
/// since = "v1beta1",
480
480
/// from_name = "prev_bar",
481
- /// from_type = "u16"
481
+ /// from_type = "u16",
482
+ /// downgrade_with = usize_to_u16
482
483
/// ))]
483
484
/// bar: usize,
484
485
/// baz: bool,
485
486
/// }
487
+ ///
488
+ /// fn usize_to_u16(input: usize) -> u16 {
489
+ /// input.try_into().unwrap()
490
+ /// }
486
491
/// ```
487
492
///
488
493
/// <details>
@@ -591,8 +596,8 @@ mod utils;
591
596
/// ### Custom conversion function at field level
592
597
///
593
598
/// As stated in the [`changed()`](#changed-action) section, a custom conversion
594
- /// function can be provided using the `convert_with` argument. A simple example
595
- /// looks like this:
599
+ /// function can be provided using the `downgrade_with` and `upgrade_with`
600
+ /// argument. A simple example looks like this:
596
601
///
597
602
/// ```
598
603
/// # use stackable_versioned_macros::versioned;
@@ -604,13 +609,13 @@ mod utils;
604
609
/// #[versioned(changed(
605
610
/// since = "v1beta1",
606
611
/// from_type = "u8",
607
- /// convert_with = "u8_to_u16 "
612
+ /// downgrade_with = "u16_to_u8 "
608
613
/// ))]
609
614
/// bar: u16,
610
615
/// }
611
616
///
612
- /// fn u8_to_u16(old: u8 ) -> u16 {
613
- /// old as u16
617
+ /// fn u16_to_u8(input: u16 ) -> u8 {
618
+ /// input.try_into().unwrap()
614
619
/// }
615
620
/// ```
616
621
///
@@ -628,7 +633,15 @@ mod utils;
628
633
/// impl ::std::convert::From<v1alpha1::Foo> for v1beta1::Foo {
629
634
/// fn from(__sv_foo: v1alpha1::Foo) -> Self {
630
635
/// Self {
631
- /// bar: u8_to_u16(__sv_foo.bar),
636
+ /// bar: __sv_foo.bar.into(),
637
+ /// }
638
+ /// }
639
+ /// }
640
+ ///
641
+ /// impl ::std::convert::From<v1beta1::Foo> for v1alpha1::Foo {
642
+ /// fn from(__sv_foo: v1beta1::Foo) -> Self {
643
+ /// Self {
644
+ /// bar: u16_to_u8(__sv_foo.bar),
632
645
/// }
633
646
/// }
634
647
/// }
@@ -718,12 +731,16 @@ use serde::{Deserialize, Serialize};
718
731
pub struct FooSpec {
719
732
#[versioned(
720
733
added(since = "v1beta1"),
721
- changed(since = "v1", from_name = "prev_bar", from_type = "u16")
734
+ changed(since = "v1", from_name = "prev_bar", from_type = "u16", downgrade_with = usize_to_u16 )
722
735
)]
723
736
bar: usize,
724
737
baz: bool,
725
738
}
726
739
740
+ fn usize_to_u16(input: usize) -> u16 {
741
+ input.try_into().unwrap()
742
+ }
743
+
727
744
# fn main() {
728
745
let merged_crd = Foo::merged_crd(Foo::V1).unwrap();
729
746
println!("{}", serde_yaml::to_string(&merged_crd).unwrap());
0 commit comments