How can I call it from rust?
#[link(name = "cryptowrapper")]
extern {
fn newCryptoclass(); // I am lost here. , how can I reconstruct this: typedef struct CryptoWrap CryptoWrap; in rust, so that I can use it like this : fn newCryptoclass() -> CryptoWrap;
fn hello_w(CryptoWrap* v); // this line is where I am even more lost. How can I reconstruct this one?
}
For this you're going to need bindgen to convert the C header to a Rust equivalent.
And then you need to figure out linking, which in Rust is as fiddly as in any C build system. #[link(name = "foo")] is equivalent of only passing -lfoo, which is usually too optimistic, since in the real-world you'll need to ensure the library is built/installed and pass -L to find it. For that you'll need build.rs script, maybe the cc crate to build C code as a static library, or pkg_config crate to find its path.
But, the problem is the Struct. I cannot initializate it without the crypto_instance field.
let mut cryptoWrapper = CryptoWrapper {}; // doesnt work, but I cannot initializate that variable crypto_instance here, when it is done in new();.
cryptoWrapper.new();
In C++, to constrict a instance you need to allocate a space first, call all the constructors of its superclasses by traversing inheritance graph, and finally call your class' constructor(initializer) with it.
In Rust, there's neither inheritance nor constructor here. The only way to construct a struct value(we prefer this term over instance), just make a struct literal and feeds all the fields it needs.
You don't even need a fn new(). It's just a function like any other like fn hello() or fn appendString(). Though we prefer this name for the function which returns the struct from simple arguments.