Skip to content

Conversation

buffalojoec
Copy link
Contributor

The Rust renderer supports a configuration object for determining what traits you'd like to be generated in the #[derive(..)] block of each type. However, if you don't include BorshSerialize or BorshDeserialize, the renderer will still use borsh::to_vec for instructions.

This PR changes those borsh::to_vec callsites in the generated instructions to instead use self.try_to_vec() and conditionally implements a try_to_vec method that calls into borsh::try_to_vec if the BorshSerialize trait is implemented.

The use of a wrapper function try_to_vec allows developers to implement their own try_to_vec as a workaround in case they want to use an alternative serialization method, such as bytemuck. This is current how the generated deserialization code for accounts works accidentally.

Copy link

changeset-bot bot commented Sep 26, 2025

🦋 Changeset detected

Latest commit: 123ae50

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/renderers-rust Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@buffalojoec buffalojoec force-pushed the optional-borsh-callsites branch from 40c7842 to c2cc799 Compare September 26, 2025 09:38
@buffalojoec buffalojoec marked this pull request as ready for review September 26, 2025 09:41
Copy link
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

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

Tysm for this! 🍺

@lorisleiva lorisleiva merged commit ac05970 into codama-idl:main Sep 26, 2025
4 checks passed
@github-actions github-actions bot mentioned this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants