25 releases

new 0.5.2 Jun 14, 2019
0.5.1 Oct 3, 2018
0.5.0 Sep 21, 2018
0.4.0 Jul 9, 2018
0.0.12 Nov 19, 2015

#12 in FFI

Download history 166/week @ 2019-03-01 257/week @ 2019-03-08 173/week @ 2019-03-15 462/week @ 2019-03-22 152/week @ 2019-03-29 153/week @ 2019-04-05 95/week @ 2019-04-12 102/week @ 2019-04-19 216/week @ 2019-04-26 183/week @ 2019-05-03 174/week @ 2019-05-10 223/week @ 2019-05-17 202/week @ 2019-05-24 160/week @ 2019-05-31 643/week @ 2019-06-07

1,001 downloads per month
Used in 12 crates (11 directly)

MIT/Apache

16KB
173 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.5"

[build-dependencies]
cpp_build = "0.5"

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
~24K SLoC