Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rust-cpp

> 编程语言
Open source

Embed C++ directly inside your rust code!

848 stars0 likes1 views
WebsiteGitHub

About

Embed C++ directly inside your rust code!

rust-cpp - Embed C++ code directly in Rust

Overview

rust-cpp is a build tool & macro which enables you to write C++ code inline in your rust code.

rust
let name = std::ffi::CString::new("World").unwrap();
let name_ptr = name.as_ptr();
let r = unsafe {
    cpp!([name_ptr as "const char *"] -> u32 as "int32_t" {
        std::cout "
}

Usage

For usage information and in-depth documentation, see the cpp crate module level documentation.

Differences with the cxx crate

This crate allows to write C++ code "inline" within your Rust functions, while with the cxx crate, you have to write a bit of boiler plate to have calls to functions declared in a different .cpp file.

Having C++ code inline might be helpful when trying to call to a C++ library and that one may wish to make plenty of call to small snippets. It can otherwise be fastidious to write and maintain the boiler plate for many small functions in different places.

These crate can also be used in together. The cxx crate offer some useful types such as CxxString that can also be used with this crate.

The cxx bridge does more type checking which can avoid some classes of errors. While this crate can only check for equal size and alignment.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustc-plus-plusffimacrosrust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言