24 releases

0.5.1 Oct 3, 2018
0.4.0 Jul 9, 2018
0.3.2 Sep 24, 2017
0.3.1 Jul 12, 2017
0.0.12 Nov 19, 2015

#11 in FFI

Download history 197/week @ 2018-11-18 291/week @ 2018-11-25 74/week @ 2018-12-02 108/week @ 2018-12-09 161/week @ 2018-12-16 119/week @ 2018-12-23 75/week @ 2018-12-30 175/week @ 2019-01-06 80/week @ 2019-01-13 61/week @ 2019-01-20 84/week @ 2019-01-27 191/week @ 2019-02-03 108/week @ 2019-02-10 111/week @ 2019-02-17 170/week @ 2019-02-24

831 downloads per month
Used in 10 crates (9 directly)

MIT/Apache

15KB
160 lines


lib.rs:

This crate cpp provides macros that allow embedding arbitrary C++ code.

Usage

This crate must be used in tandem with the cpp_build crate. A basic Cargo project which uses these projects would have a structure like the following:

crate
|-- Cargo.toml
|-- src
    |-- lib.rs
|-- build.rs

Where the files look like the following:

Cargo.toml

[package]
build = "build.rs"

[dependencies]
cpp = "0.4"

[build-dependencies]
cpp_build = "0.4"

build.rs

extern crate cpp_build;

fn main() {
    cpp_build::build("src/lib.rs");
}

lib.rs

#[macro_use]
extern crate cpp;

cpp!{{
    #include <stdio.h>
}}

fn main() {
    unsafe {
        cpp!([] {
            printf("Hello, World!\n");
        });
    }
}

Dependencies

~1MB
~23K SLoC