Skip to content

#ffi

11 posts tagged ffi. All posts

  1. RustCalling C functions from Rust with FFI and the cc crateCompile a small C file with a Cargo build script, declare it in an unsafe extern block, and call it from Rust, including passing strings with CString.
  2. RustWrite a procedural macro in Rust: a custom assert_equals! with syn and quoteBuild a function-like procedural macro that compares two expressions and prints both values on failure, and compare it with a macro_rules! version.
  3. Rustserde_json basics: converting Rust structs to and from JSONAdd serde and serde_json to a Rust project, derive Serialize and Deserialize, and convert structs to and from JSON strings with error handling.
  4. RustUnsafe Rust basics: raw pointers and calling C's malloc and freeWhat the unsafe keyword allows in Rust, with two examples, dereferencing a raw pointer and managing a buffer with libc's malloc and free, plus the rules you must uphold.
  5. RustRust and other languages: FFI, WebAssembly, and gRPC comparedThree ways to make Rust work with other languages: in-process calls over the C ABI, compiling to WebAssembly, and gRPC services over the network.
  6. RustCalling C and C++ code from Rust with FFI and the cc crateCompile C and C++ sources with the cc crate, declare them in Rust with extern "C", pass strings safely with CString, and wrap C++ classes in C functions.
  7. RustSharing data between threads in Rust with Arc and MutexUse Arc<Mutex<T>> to let several threads update one Vec safely, plus when an atomic or a channel is the better synchronization primitive.
  8. RustBuilding a TCP chat server and client in Rust with std::netA small multi-client chat program using only Rust's standard library: TcpListener, one thread per client, and a shared map of connections for broadcasting.
  9. RustGetting started with Rocket 0.5: routes, catchers and Tera templatesSet up a Rocket 0.5 web app in Rust on stable: define routes, add a custom 404 catcher, and render HTML with rocket_dyn_templates and Tera.
  10. RustHashing strings with SHA-256 and SHA-512 in Rust using the sha2 crateA small Rust program that reads a line from stdin and prints its SHA-256 and SHA-512 digests as hex, using the RustCrypto sha2 and hex crates.
  11. RustBuild a command-line weather app in Rust with reqwest and OpenWeatherMapA small Rust CLI that looks up current weather by city name from the OpenWeatherMap API, using reqwest's blocking client and serde for JSON.

© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)