无法共享C++使用CXX桥与生锈结构
我了解C ++ 类
必须隐藏在指针后面(*mut
,sharedptr< t>
等)。但是结构似乎应该是“ c”。
我正在尝试导出
如果我将struct定义放在CXX桥模块的根部中,例如:
#[cxx::bridge(namespace = "RDKit")]
pub mod ffi {
pub struct CleanupParameters {
rdbase: String,
}
unsafe extern "C++" { /* snip */ }
}
我会收到编译器错误:
warning: ..../rdkit-sys/src/cxx/bridge/mol_standardize.rs.cc:87:10: error: definition of type 'CleanupParameters' conflicts with type alias of the same name
warning: struct CleanupParameters;
warning: ^
这很有意义,就像我在定义新的cleanupparameters
而不是“采用” C ++定义,因此碰撞的名称很有意义。
但是,如果我试图将定义移至外部区块:
#[cxx::bridge(namespace = "RDKit")]
pub mod ffi {
unsafe extern "C++" {
pub struct CleanupParameters {
rdbase: String,
}
}
}
CXX Bridge Proc Macro不允许语言:
error[cxxbridge]: expected one of: `fn`, `static`, `type`
┌─ src/cxx/bridge/mol_standardize.rs:7:13
│
7 │ pub struct CleanupParameters {
│ ^^^^^^ expected one of: `fn`, `static`, `type`
这没有多大意义。如何将C ++的“非不透明”结构共享为Rust?
I understand C++ class
definitions must be hidden behind a pointer (*mut
, SharedPtr<T>
, etc). But structs seem like they should be "C like".
I am trying to export CleanupParameters to the Rust side of the binding.
If I put the struct definition in the root of the CXX bridge module like:
#[cxx::bridge(namespace = "RDKit")]
pub mod ffi {
pub struct CleanupParameters {
rdbase: String,
}
unsafe extern "C++" { /* snip */ }
}
I get the compiler error:
warning: ..../rdkit-sys/src/cxx/bridge/mol_standardize.rs.cc:87:10: error: definition of type 'CleanupParameters' conflicts with type alias of the same name
warning: struct CleanupParameters;
warning: ^
which makes sense, it's like I'm defining a new CleanupParameters
and not "adopting" the C++ definition, so the name collision makes sense.
But if I try to move the definition in to the extern block:
#[cxx::bridge(namespace = "RDKit")]
pub mod ffi {
unsafe extern "C++" {
pub struct CleanupParameters {
rdbase: String,
}
}
}
the language is not allowed by the CXX bridge proc macro:
error[cxxbridge]: expected one of: `fn`, `static`, `type`
┌─ src/cxx/bridge/mol_standardize.rs:7:13
│
7 │ pub struct CleanupParameters {
│ ^^^^^^ expected one of: `fn`, `static`, `type`
which does not make much sense. How can I share "non opaque" structs from C++ into Rust?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论