mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.43k stars 315 forks source link

Add rename-all=prefix: #1007

Closed jsgf closed 4 weeks ago

jsgf commented 1 month ago

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 commented 1 month ago

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).