Yongheng Chen | e940de9 | 2024-07-17 09:36:19 -0700 | [diff] [blame] | 1 | # Attributes to fine-tune generated bindings |
| 2 | |
| 3 | Crubit recognizes custom attributes to fine-tune generated bindings. |
| 4 | |
| 5 | To use a Crubit attribute, you must add the following to your Rust crate: |
| 6 | |
| 7 | ```rust |
| 8 | |
| 9 | #![feature(register_tool)] |
| 10 | #![register_tool(__crubit)] |
| 11 | ``` |
| 12 | |
| 13 | The format of the Crubit tool attributes is `#[__crubit::annotate(attribute_name="attribute_value")]`. |
| 14 | |
| 15 | ## `cpp_name` |
| 16 | |
| 17 | This attribute overrides the name of the generated C++ bindings. For |
| 18 | example, the following Rust code: |
| 19 | |
| 20 | ```rust |
| 21 | #[__crubit::annotate(cpp_name="Create")] |
| 22 | pub fn new() -> i32 {...} |
| 23 | ``` |
| 24 | |
| 25 | Will generate the following C++ bindings: |
| 26 | |
| 27 | ```cpp |
| 28 | std::int32_t Create(); // named `Create` instead of `new`. |
| 29 | ``` |
| 30 | |
| 31 | Currently this attribute works on functions only (See b/349070421). |
| 32 | |
Yongheng Chen | d5a6784 | 2024-07-19 13:57:35 -0700 | [diff] [blame^] | 33 | ## `cpp_type` |
Yongheng Chen | e940de9 | 2024-07-17 09:36:19 -0700 | [diff] [blame] | 34 | |
| 35 | TODO(b/315382130): Rename this attribute to `cpp_type` and add the doc. |