c_import

This is a small crate providing a cimport macro (also a cppimport macro), which can be used to import C headers into your program. You need bindgen to be installed in your system.

Usage

In your Cargo.toml: ```toml

Cargo.toml

[depenedencies] c_import = "0.1" ```

In your Rust source file: ```rust // src/main.rs use cimport::cimport;

c_import!();

fn main() { let version = unsafe { cairo_version() }; println!("{}", version); } ```

In your Rust build script: rust // build.rs fn main() { println!("cargo:rustc-link-lib=cairo"); }

Using non-system headers is also possible via enclosing the header path with quotation marks: ```rust // src/main.rs use cimport::cimport; cimport!("src/myheader.h");

fn main() { let version = unsafe { cairo_version() }; println!("{}", version); } ```

Usage with C++ headers (limited)

```rust // src/main.rs use cimport::cppimport;

cpp_import!();

fn main() { let version = unsafe { Fl::api_version() }; println!("{}", version); } ```

rust // build.rs fn main() { println!("cargo:rustc-link-lib=fltk"); }

Another example showing how to deal with C++ namespaces:

```cpp // src/my_header.hpp

pragma once

namespace mynamespace { class MyStruct { int version; public: MyStruct(int version); int version() const; }; } ```

```rust // src/main.rs use cimport::cppimport;

cppimport!("src/myheader.hpp");

fn main() { let h = unsafe { mynamespaceMyStruct::new(2) }; println!("{}", unsafe { h.version() }); } ```

Limitations