1

embed-c:可将C代码直接嵌入到Rust代码中

 2 years ago
source link: https://www.jdon.com/59164
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

embed-c:可将C代码直接嵌入到Rust代码中

embed-c是一个让你在 Rust 代码文件中嵌入C 码的crate。C 代码在编译时使用C2Rust翻译成Rust代码,这意味着它可以与 Rust 完全互操作。C 代码可以调用 Rust 代码,反之亦然。
#![feature(rustc_private)] 

use embed_c::embed_c;

embed_c! {
    int add(int x, int y) {
        return x + y;
    }
}

fn main() {
    let x = unsafe { add(1, 2) };
    println!("{}", x);
}
D语言采取了不同的方法:AC编译器是D编译器二进制文件的一部分,称为 ImportC。它将标准 C11 代码编译成AST,然后交给 D 编译器。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK