How can I call a C ++ constructor via Rust FFI?

I am trying to use "xerces-c" via FFI in Rust with no success. In C ++, I would write the following code to use it:

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();

      

How can I use these "complex" data types in Rust? I found many examples for exporting / building FFI to use in other languages, but none have used complex types in Rust.

extern crate libc;

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

      

+3


source to share


1 answer


Rust doesn't support FFI from C ++. If you want to use this library, you will need to find or write a translation layer that provides a pure C interface to the library and then links to that.



+6


source







All Articles