hicc
A Rust FFI SDK that easily and efficiently enables the calling of any c++ api function, while significantly increasing the memory safety of c++ api interfaces.
-------- --------------------------- ------------------ --------
| rust | ---rust api---| c++ abi declare with rust | | c++ abi declare |---c++ api---| c++ |
------- --------------------------- ------------------ --------
| |
----------------- ---------------
| hicc rust sdk |-----c abi-----| hicc c++ sdk |
----------------- | ---------------
|
----------------- |
| hicc js sdk | --------
-----------------
版本变更说明
v0.1.5
- 支持纯函数, 以及纯函数的重载(
CALL_REMOTE_MTHOD), 参见examples/virtual.
v0.1.4
- 修复bug:
rust实现的虚函数中包括非值传递的类类型存在错误.
v0.1.3
修复v0.1.2的bug: EXPORT_METHOD/EXPORT_MEMBER_METHOD支持数据读写存在bug,回退此功能.
EXPORT_DATA支持全局变量,EXPORT_MEMBER_DATA支持类的数据成员可写引用. 参见examples/datasEXPORT_CONST_DATA支持全局变量,EXPORT_MEMBER_CONST_DATA支持类的数据成员的只读引用. 参见examples/datas- 支持数组,等同于指针处理.
v0.1.2(不可用)
EXPORT_METHOD支持全局变量,EXPORT_MEMBER_METHOD支持类的数据成员. 参见examples/datas
v0.1.1
EXPORT_METHOD支持变长参数的函数,无需使用EXPORT_VARIADIC.- 消除包含
va_list和...函数的参数数量约束.
支持的功能介绍
支持的数据类型.
| 数据类型 | 是否支持 | 备注 |
|---|---|---|
T |
support | |
const T& |
support | |
T& |
support | |
T&& |
support | rust侧同T |
const T* |
support | 程序员管理资源生命周期 |
T* |
support | 程序员管理资源生命周期 |
const T**多重指针 |
support | 程序员管理资源生命周期 |
T**多重指针 |
support | 程序员管理资源生命周期 |
std::function<R(ArgTypes...)> |
support |
说明:
rust侧忽略volatile.
支持的函数类型.
| 函数分类 | 是否支持 |
|---|---|
funtion(external linkage/internal linkage/no linkage) |
support |
| function overloading | support |
| default parameters | support |
| template function | support |
| class member function | support |
noexcept(false) |
support |
| template class | support |
dynamic_cast |
support |
| realizing virtual function with rust | support |
va_list |
support |
variadic(...) |
partial support(仅全局函数,参数和返回值无类类型) |
安全性保证和增强
基于rust生命周期机制,可增强c++接口的安全性.
c++容器的迭代器是一个典型的例子.
template<class T, class Allocator> class vector {
//...
iterator begin();
};
可映射为如下rust接口:
hicc::import_class! {
pub class vector<T> {
// ...
fn begin(&mut self) -> &mut VecIter<T>;
}
pub class VecIter<T> {
//...
}
}
迭代器和容器的生命周期关联起来,基于rust的借用规则,增强了接口的安全性.
开发指南.
详细内容参见cargo doc生成的文档.
可参考examples目录下的样例,模板类可参考hicc-std的实现.
约束: 依赖c++11及更高版本的特性.