Skip to content

Conversation

Techassi
Copy link
Member

This PR adds a new argument convert_with to the changed() action. It allows users to customize the conversion function used on a field level. This is useful when auto-generated From impl between versions should be kept, but individual fields need custom conversions instead of using the default .into() call.

Example

#[versioned(
    version(name = "v1alpha1"),
    version(name = "v1beta1")
)]
pub struct Foo {
    #[versioned(changed(
        since = "v1beta1",
        from_type = "u8",
        convert_with = "u8_to_u16"
    ))]
    bar: u16,
}

fn u8_to_u16(old: u8) -> u16 {
    old as u16
}

Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@sbernauer sbernauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice quality of life feature!

@Techassi Techassi added this pull request to the merge queue Feb 25, 2025
Merged via the queue into main with commit 15faafd Feb 25, 2025
10 checks passed
@Techassi Techassi deleted the feat/stackable-versioned-custom-field-conversion-func branch February 25, 2025 08:40
@lfrancke lfrancke moved this from Development: Done to Done in Stackable Engineering Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants