Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rename-all=prefix: #1007

Closed
wants to merge 1 commit into from
Closed

Conversation

jsgf
Copy link
Contributor

@jsgf jsgf commented Oct 4, 2024

This adds a new rename-all annotation which allows setting a specific prefix to all fields. For example:

/// cbindgen:rename-all=prefix:ERR_
#[repr(i32)]
pub enum Error {
   BAD = 0,
   VERY_BAD = 1
}

While in principle this can be added to the config file, it's primarily useful for overrides on a case-by-case basis.

@jsgf jsgf force-pushed the add-prefix-annotation branch from b68be3e to b4a40d8 Compare October 4, 2024 02:08
This adds a new rename-all annotation which allows setting a specific
prefix to all fields. For example:

```rust
/// cbindgen:rename-all=prefix:ERR_
enum Error {
   Bad = 0,
   VeryBad = 1
}
```

While in principle this can be added to the config file, it's primarily
useful for overrides on a case-by-case basis.
@jsgf jsgf force-pushed the add-prefix-annotation branch from b4a40d8 to 3a3928d Compare October 4, 2024 02:11
@jsgf
Copy link
Contributor Author

jsgf commented Oct 4, 2024

Alternatively (and perhaps preferably) this could be a separate option which is applied after the normal rename rule so you can both rename and add a prefix (which could be applied after prefix-with-name or exclusive with it).

facebook-github-bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request Oct 4, 2024
Summary: [Fix an upstream bug](mozilla/cbindgen#1006) and [add ability to put arbitrary prefix on field names](mozilla/cbindgen#1007).

Reviewed By: jasonwhite

Differential Revision: D63878067

fbshipit-source-id: 16a35ed1fa2adc4c9211fc6f6332f0be7dbf4f56
facebook-github-bot pushed a commit to facebook/sapling that referenced this pull request Oct 4, 2024
Summary: [Fix an upstream bug](mozilla/cbindgen#1006) and [add ability to put arbitrary prefix on field names](mozilla/cbindgen#1007).

Reviewed By: jasonwhite

Differential Revision: D63878067

fbshipit-source-id: 16a35ed1fa2adc4c9211fc6f6332f0be7dbf4f56
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request Oct 4, 2024
Summary: [Fix an upstream bug](mozilla/cbindgen#1006) and [add ability to put arbitrary prefix on field names](mozilla/cbindgen#1007).

Reviewed By: jasonwhite

Differential Revision: D63878067

fbshipit-source-id: 16a35ed1fa2adc4c9211fc6f6332f0be7dbf4f56
Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

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

This is fine for now :)

@@ -171,7 +171,7 @@ impl Item for Union {
let rules = self
.annotations
.parse_atom::<RenameRule>("rename-all")
.unwrap_or(config.structure.rename_fields);
.unwrap_or(config.structure.rename_fields.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe avoid these clones by:

let rules = self.annotations.parse_atom::<>();
let rules = rules.as_ref().unwrap_or(&config.structure.rename_fields);

But fine either way.

@emilio emilio mentioned this pull request Oct 27, 2024
@emilio emilio closed this in #1021 Oct 27, 2024
@jsgf jsgf deleted the add-prefix-annotation branch October 28, 2024 19:08
facebook-github-bot pushed a commit to facebook/dotslash that referenced this pull request Oct 29, 2024
Summary:
PRs mozilla/cbindgen#1006
mozilla/cbindgen#1007 were accepted, so update patch to
upstream git repo until next release is cut.

Also bump `syn` to match cbindgen.

Reviewed By: dtolnay

Differential Revision: D65079945

fbshipit-source-id: 5b9f0467150d7cf81f5a9df0bb4d0c1309e67e1b
facebook-github-bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request Oct 29, 2024
Summary:
PRs mozilla/cbindgen#1006
mozilla/cbindgen#1007 were accepted, so update patch to
upstream git repo until next release is cut.

Also bump `syn` to match cbindgen.

Reviewed By: dtolnay

Differential Revision: D65079945

fbshipit-source-id: 5b9f0467150d7cf81f5a9df0bb4d0c1309e67e1b
facebook-github-bot pushed a commit to facebook/sapling that referenced this pull request Oct 29, 2024
Summary:
PRs mozilla/cbindgen#1006
mozilla/cbindgen#1007 were accepted, so update patch to
upstream git repo until next release is cut.

Also bump `syn` to match cbindgen.

Reviewed By: dtolnay

Differential Revision: D65079945

fbshipit-source-id: 5b9f0467150d7cf81f5a9df0bb4d0c1309e67e1b
facebook-github-bot pushed a commit to facebookincubator/reindeer that referenced this pull request Oct 29, 2024
Summary:
PRs mozilla/cbindgen#1006
mozilla/cbindgen#1007 were accepted, so update patch to
upstream git repo until next release is cut.

Also bump `syn` to match cbindgen.

Reviewed By: dtolnay

Differential Revision: D65079945

fbshipit-source-id: 5b9f0467150d7cf81f5a9df0bb4d0c1309e67e1b
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request Oct 29, 2024
Summary:
PRs mozilla/cbindgen#1006
mozilla/cbindgen#1007 were accepted, so update patch to
upstream git repo until next release is cut.

Also bump `syn` to match cbindgen.

Reviewed By: dtolnay

Differential Revision: D65079945

fbshipit-source-id: 5b9f0467150d7cf81f5a9df0bb4d0c1309e67e1b
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