dev note #1: toast
This is a dev note, a new type of post I'm trying out. In these posts I'll share interesting dev things I've learned, or small projects I've built.
To kick off this first edition of dev notes, here's toast, a CLI app I put together to monitor thermal pressure/throttling on my Mac. I'm equator-side right now and my laptop is definitely on the struggle bus due to the heat, and reading this article about building MacThrottle, a menu bar app that tracks thermal pressure, inspired me to build a simple CLI app to show when my Mac was throttling.
PSA: Go check out that post if you're interested in a great technical write up about the messy world of reading thermal states on MacOS!

toast was also inspired by thinking it would be a good first project to try out Claude Code with. I finally caved and paid for Claude to see what the fuss is about. How did it do? Passably well: I got a working app pretty quickly, though there was a lot of follow-up prompting to clean up the code and add more features and usability. And then there was still a good amount of hands-on tweaking and cleanup, particularly as I wanted to open source it.
In taking the time to understand the generated code, one interesting thing I learned is that the notify APIs I needed, e.g. notify_register_check, are provided by libSystem, and rustc always links to that by default. That's why my extern block does not require a #[link] directive for the FFI to work.
// no link directive
unsafe extern "C" {
fn notify_register_check(name: *const c_char, out_token: *mut c_int) -> c_uint;
fn notify_get_state(token: c_int, state: *mut u64) -> c_uint;
fn notify_cancel(token: c_int) -> c_uint;
}
Here, I use otool to show libSystem is linked to by my compiled app:
$ otool -L target/debug/toast
target/debug/toast:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 4201.0.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
Linking quirk aside, if you're interested in dipping a toe into Rust FFI, the source for toast is a quick and helpful read. It's simple, uses only a handful of C APIs, and introduces concepts like extern, unsafe, C types (e.g. c_char), and raw pointers (*const and *mut). I should write a dev note about raw pointers at some point (hah), it took me a while to realize those were special and not just some other reference type.