flapigen-rs: rust 与其他语言交互的工具
目前支持 C++ 和 Java ,也可以自己开发对应语言接口
比如,以下 Rust 代码:
struct Foo {
data: i32
}
impl Foo {
fn new(val: i32) -> Foo {
Foo{data: val}
}
fn f(&self, a: i32, b: i32) -> i32 {
self.data + a + b
}
fn set_field(&mut self, v: i32) {
self.data = v;
}
}
fn f2(a: i32) -> i32 {
a * 2
}
然后就可以写这样的 Java 代码:
Foo foo = new Foo(5);
int res = foo.f(1, 2);
assert res == 8;
或者是这样的 C++ 代码:
Foo foo(5);
int res = foo.f(1, 2);
assert(res == 8);
https://github.com/Dushistov/flapigen-rs
Rust 常量泛型要来了:#![feature(min_const_generics)] 将在 Rust 1.50 版本中稳定
例子如下:
#![feature(min_const_generics)]
trait Foo<const N: usize> {
fn method<const M: usize>(&mut self, arr: [[u8; M]; N]);
}
struct Bar<T, const N: usize> {
inner: [T; N],
}
impl<const N: usize> Foo<N> for Bar<u8, N> {
fn method<const M: usize>(&mut self, arr: [[u8; M]; N]) {
for (elem, s) in self.inner.iter_mut().zip(arr.iter()) {
for &x in s {
*elem &= x;
}
}
}
}
fn function<const N: u16>() -> u16 {
// Const parameters can be used freely inside of functions.
(N + 1) / 2 * N
}
fn main() {
let mut bar = Bar { inner: [0xff; 3] };
// This infers the value of `M` from the type of the function argument.
bar.method([[0b11_00, 0b01_00], [0b00_11, 0b00_01], [0b11_00, 0b00_11]]);
assert_eq!(bar.inner, [0b01_00, 0b00_01, 0b00_00]);
// You can also explicitly specify the value of `N`.
assert_eq!(function::<17>(), 153);
}
https://github.com/rust-lang/rust/pull/79135
九个在生产环境中使用 Rust 的公司
包括 Microsoft 、npm、Facebook、Amazon、Discord等
https://serokell.io/blog/rust-companies
emoji:unicode emoji 库
https://docs.rs/emoji/0.1.1/emoji/
From 日报小组 @挺肥
社区学习交流平台订阅:
1
共 0 条评论, 1 页
评论区
写评论还没有评论