如何通过Rust FFI调用C++构造函数?

arc*_*hos 3 c++ ffi rust

我试图通过FFI在Rust中使用"xerces-c"而没有成功.在C++中,我会编写以下代码来使用它:

XMLPlatformUtils::Initialize();
{
  XercesDOMParser domParser;
  ParserErrorHandler parserErrorHandler;

  domParser.setErrorHandler(&parserErrorHandler);
  domParser.setDoSchema(true);
  domParser.setValidationSchemaFullChecking(true);

  domParser.parse(xmlFilePath.c_str());
  if(domParser.getErrorCount() != 0) {     
     // ...
  }
}
XMLPlatformUtils::Terminate();
Run Code Online (Sandbox Code Playgroud)

如何在Rust中使用这些"复杂"数据类型?我找到了许多导出/创建FFI以在其他语言中使用它的示例,但没有在Rust中使用复杂类型.

extern crate libc;

#[link(name = "xerces-c")]
extern {
    // How do i have to implement the constructor here? 
}
Run Code Online (Sandbox Code Playgroud)

DK.*_*DK. 6

Rust不支持使用C++的FFI.如果你想使用这个库,你将不得不寻找或编写一个转换层,提供了一个纯粹的C接口库,然后绑定到那个.