История изменений
Исправление
vertexua,
(текущая версия)
:
Я царь
Возрадуйся, тут C++ в Rust подвезли
[package]
name = "capp1"
version = "0.1.0"
edition = "2018"
[dependencies]
cpp="0.5"
[build-dependencies]
cpp_build = "0.5"
build.rs
fn main() {
cpp_build::build("src/main.rs");
}
main.rs
use cpp::cpp;
cpp! {{
#include <iostream>
}}
fn sum(a: i32, b: i32) -> i32 {
unsafe {
return cpp!([a as "int32_t", b as "int32_t"] -> i32 as "int32_t" {
const auto res = a + b;
std::cout << "Computing sum "
<< a << "+" << b << "=" << res
<< "..." << std::endl;
return res;
});
}
}
fn main() {
let a = 10;
let b = 20;
let res = sum(a, b);
println!("{} + {} = {}", a, b, res);
}
Исходная версия
vertexua,
:
Я царь
Возрадуйся, тут C++ в Rust подвезли
use cpp::cpp;
cpp! {{
#include <iostream>
}}
fn sum(a: i32, b: i32) -> i32 {
unsafe {
return cpp!([a as "int32_t", b as "int32_t"] -> i32 as "int32_t" {
const auto res = a + b;
std::cout << "Computing sum "
<< a << "+" << b << "=" << res
<< "..." << std::endl;
return res;
});
}
}
fn main() {
let a = 10;
let b = 20;
let res = sum(a, b);
println!("{} + {} = {}", a, b, res);
}