How it works...
Enhancing Python's capabilities with Rust is a great way to get the best of both worlds: Python is famously easy to learn and use; Rust is fast and safe (and does not fail at runtime as easily).
In steps 1 to 3, we again create a dynamic native library that creates an SHA256 hash out of a provided string argument. The required changes in Cargo.toml and lib.rs are the same as if we were to create a library for C/C++ inter-op: #[no_mangle]. The Including legacy C code recipe earlier in this chapter describes the inner workings in more detail, so be sure to read the How it works... section there as well.
The cdylib library type describes a dynamic library for C, and other types are available for different purposes. Check out ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access