Hacker News new | ask | show | jobs
by npalli 671 days ago

   So, Zngur allows you to use arbitrary Rust types in C++, store them by value in the C++ stack, and call arbitrary Rust methods and functions on them. But it doesn't bridge any C++ type into Rust, since it is not possible with the same ergonomic
You want to use C++ libraries from Rust. This only does interop the other way.
3 comments

Zngur does allow you to execute arbitrary C++ from Rust.

Unfortunately it chooses to just assume your C++ is sound, it does explicitly warn you that you're signing up for this, but realistically this just doubles down on the known bad assumption in C++ that programmers are infallible.

Rather than (like Rust's native C FFI) marking the arbitrary C++ as unsafe, Zngur chooses to have you explicitly opt in if you want your code marked unsafe. We know from years of practical experience that C++ programmers rely heavily on unstated assumptions for the correctness of code, a practice which does not scale. A very large proportion of the C++ stdlib itself has a narrow contract, yet few practitioners memorise these contracts and they're unchecked - disaster looms.

For calling C++ libraries from Rust, there is also https://crates.io/crates/cpp
It seems to do both:

https://hkalbasi.github.io/zngur/tutorial.html#calling-c-fro...

It sound like your quoted text is just saying that it’s not as ergonomic, you cannot use arbitrary C++ types directly in Rust, but you can use arbitrary Rust types in C++.