@@ -478,11 +478,16 @@ mod utils;
478478/// #[versioned(changed(
479479/// since = "v1beta1",
480480/// from_name = "prev_bar",
481- /// from_type = "u16"
481+ /// from_type = "u16",
482+ /// downgrade_with = usize_to_u16
482483/// ))]
483484/// bar: usize,
484485/// baz: bool,
485486/// }
487+ ///
488+ /// fn usize_to_u16(input: usize) -> u16 {
489+ /// input.try_into().unwrap()
490+ /// }
486491/// ```
487492///
488493/// <details>
@@ -591,8 +596,8 @@ mod utils;
591596/// ### Custom conversion function at field level
592597///
593598/// 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:
596601///
597602/// ```
598603/// # use stackable_versioned_macros::versioned;
@@ -604,13 +609,13 @@ mod utils;
604609/// #[versioned(changed(
605610/// since = "v1beta1",
606611/// from_type = "u8",
607- /// convert_with = "u8_to_u16 "
612+ /// downgrade_with = "u16_to_u8 "
608613/// ))]
609614/// bar: u16,
610615/// }
611616///
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()
614619/// }
615620/// ```
616621///
@@ -628,7 +633,15 @@ mod utils;
628633/// impl ::std::convert::From<v1alpha1::Foo> for v1beta1::Foo {
629634/// fn from(__sv_foo: v1alpha1::Foo) -> Self {
630635/// 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),
632645/// }
633646/// }
634647/// }
@@ -718,12 +731,16 @@ use serde::{Deserialize, Serialize};
718731pub struct FooSpec {
719732 #[versioned(
720733 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 )
722735 )]
723736 bar: usize,
724737 baz: bool,
725738}
726739
740+ fn usize_to_u16(input: usize) -> u16 {
741+ input.try_into().unwrap()
742+ }
743+
727744# fn main() {
728745let merged_crd = Foo::merged_crd(Foo::V1).unwrap();
729746println!("{}", serde_yaml::to_string(&merged_crd).unwrap());
0 commit comments