https://github.com/jiegec/cdefines
Turn #define C codes into Rust constants.
https://github.com/jiegec/cdefines
rust-macro
Last synced: about 2 months ago
JSON representation
Turn #define C codes into Rust constants.
- Host: GitHub
- URL: https://github.com/jiegec/cdefines
- Owner: jiegec
- Created: 2019-05-12T08:56:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-05T01:39:22.000Z (almost 3 years ago)
- Last Synced: 2025-03-07T12:36:22.494Z (2 months ago)
- Topics: rust-macro
- Language: Rust
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cdefines
Turn `#define` C codes into Rust constants.
## How to use:
Add to code:
```rust
extern crate cdefines;#[cdefines::preprocessor]
const IOCTL: &str =
"#define TCGETS 0x5401
#define TCSETS 0x5402
#define TCSETSW 0x5403
#define TCSETSF 0x5404";
```It gets translated to:
```rust
const IOCTL_TCGETS: usize = 0x5401;
// ...
enum IOCTL {
TCGETS = 0x5401,
// ...
}
```## What is supported
1. Plain integers(hex, oct, bin, dec) e.g. `#define A 0x1234`.
2. Simple define cascading e.g. `#define A 123` and then `#define B A`.