Skip to content

feat(stackable-versioned): Add convert_with arg in changed action#967

Merged
Techassi merged 2 commits into
mainfrom
feat/stackable-versioned-custom-field-conversion-func
Feb 25, 2025
Merged

feat(stackable-versioned): Add convert_with arg in changed action#967
Techassi merged 2 commits into
mainfrom
feat/stackable-versioned-custom-field-conversion-func

Conversation

@Techassi
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread crates/stackable-versioned-macros/src/codegen/item/field.rs
Copy link
Copy Markdown
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
@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.

4 participants