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

Rename items with a rule #703

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cormacrelf
Copy link
Contributor

Everything else can have a rename rule. Why not items too!

Example below. Nice and neat, no #![allow(non_camel_case_types)] required.

#[repr(c)]
struct StructDef {
    x: i32,
    y: f32,
}
type TypeAlias = StructDef;
// doesn't apply to functions, obviously
// also this PR fixes misleading example in docs for [export.rename] which purported to apply to a function name
#[no_mangle]
extern "C" fn capi_write(obj: *mut StructDef) {}
[export]
prefix = "capi_"
rename_items = "snake_case"
typedef struct {
    int32_t x;
    float y;
} capi_struct_def;
typedef capi_struct_def capi_type_alias;
void capi_write(capi_struct_def *def);

@cormacrelf
Copy link
Contributor Author

I realised this is a dupe of #419. This one has tests though.

#include <stdint.h>
#include <stdlib.h>

#define capi_constant_abc 10
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically the use case for allowing one rule per item type as well as a default global one. I don't often see lower_snake_case #defines in C, even in a largely lower_snake_case API. This PR already has the infrastructure for that, passing IdentifierType in to ExportConfig::rename, but hasn't implemented it (yet).

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.

So this looks probably ok, but wouldn't it be more consistent to just add a ConstantConfig::rename field of sorts? I think the point was that some constants might want to be static and can't be renamed, so that might be a bit trickier.

@orium
Copy link

orium commented Nov 2, 2022

Hi. Any change of getting this merged/release soon?

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.

None yet

3 participants