Skip to content

Conversation

@sfackler
Copy link
Member

@sfackler sfackler commented Nov 12, 2025

Before this PR

Like in Conjure-Java, we made generated objects immutable with a builder API. This makes the structs a bit more annoying to work with, since you can't directly mutate them and can't move out of them. Since Rust has a robust ownership model, the need for immutable types is not as large as it is in Java.

After this PR

==COMMIT_MSG==
Added a publicFields codegen option that replaces struct accessor methods with public fields.
==COMMIT_MSG==

The builder types are still around, and since we mark the structs #[non_exhaustive], are the only way to construct objects. This makes it a bit easier to add new fields to objects without breaking builds, and are generally a bit easier to work with since the builder methods handle things like type conversions.

To preserve backwards compatibility, the option is disabled by default, but I think we may want to make this how we do things moving forward.

Possible downsides?

We're now publicly exposing the fact that struct and union fields are boxed internally. We do this to both keep the shallow struct size from getting too enormous and to avoid infinite sizes for recursive APIs.

Closes #304

@sfackler sfackler requested a review from a team November 12, 2025 01:18
@changelog-app
Copy link

changelog-app bot commented Nov 12, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Added a publicFields codegen option that replaces struct accessor methods with public fields.

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link

changelog-app bot commented Nov 12, 2025

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

✨ Features

  • Added a publicFields codegen option that replaces struct accessor methods with public fields. (#522)

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.

Add setters to object codegen

2 participants