Skip to content

b-r-u/c2rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c2rust

Converts C function definitions to Rust. Use this tool to help in the creation of foreign function interfaces.

Pros

  • super simple
$ ./c2rust.py "int foo(const char *s, unsigned long len)"
pub fn foo(s: *const c_char, len: c_ulong) -> c_int;

Cons

Does not handle:

  • C preprocessor instructions
    • #include
    • macros
  • variadic functions
  • ...

For a more sophisticated tool take a look at rust-bindgen.

Usage

$ ./c2rust.py --help
usage: c2rust.py [-h] [-f PATH] [-s] [-c] [cfunctions]

Convert C function definitions to Rust.
Use this tool to help in the creation of foreign function interfaces.

positional arguments:
cfunctions            C function definitions

optional arguments:
-h, --help            show this help message and exit
-f PATH, --file PATH  specify path to file containing C functions
-s, --stdin           read C functions from standard input
-c, --show-c          print corresponding C functions next to Rust functions

EXAMPLES:
./c2rust.py "int foo(int x, const char *s)"

./c2rust.py -f cfunctions.txt

cat cfunctions.txt | ./c2rust.py -s

License

MIT, see LICENSE file

About

Simple tool to convert C function definitions to Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages