【发布时间】:2018-01-14 08:24:20
【问题描述】:
我试图通过 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();
如何在 Rust 中使用这些“复杂”的数据类型?我发现了许多导出/创建 FFI 以在其他语言中使用它的示例,但没有一个示例可以在 Rust 中使用复杂类型。
extern crate libc;
#[link(name = "xerces-c")]
extern {
// How do i have to implement the constructor here?
}
【问题讨论】: