Open Source

Rust CAD: Building Nuts with cadrum

Forget the boilerplate – a developer just modeled a physical nut in Rust, proving code can sculpt reality. It’s a subtle signal, but this is how foundational shifts begin.

A four-view diagram of a 3D-rendered M2 hex nut, showing isometric, front, top, and right projections.

Key Takeaways

  • The Rust `cadrum` crate enables programmatic B-rep modeling, allowing developers to create complex 3D geometry.
  • Iterative development with immediate visual feedback (PNGs and STEP files) is crucial for CAD accuracy.
  • Practical engineering challenges, like thread minor radius and chamfer creation, highlight the realism of the modeling process.
  • This project signals a broader trend of integrating computational design with software development, paving the way for AI-driven physical object creation.

We’ve all been waiting. Not just for faster compiles or cooler APIs, but for that moment when software stops feeling like abstract logic and starts touching the real world in a tangible, almost alchemical way. For years, the dream of building complex physical objects entirely within code felt like science fiction. Then, someone tinkers with a hex nut in Rust. And suddenly, the future feels a lot closer.

What was the expectation? A new framework that helps you manage Kubernetes manifests more efficiently, maybe? Or another AI model that can write better SQL? Those are important, sure. But what if the real platform shift isn’t just about managing systems, but about building them, atom by atom, right from your IDE? That’s precisely the undercurrent buzzing beneath this seemingly niche endeavor: the creation of an M2 hex nut using the Rust <a href="/tag/cadrum/">cadrum</a> crate.

From Pixels to Physicality: A Digital Forge

This isn’t just a code snippet; it’s a digital blueprint for a tiny piece of the physical universe. The developer behind this project took on the task of modeling an ISO 4032 M2 hex nut, a piece of hardware so ubiquitous it’s practically invisible until you need it. The tool? cadrum, an OpenCASCADE-based Boundary Representation (B-Rep) library in Rust. The outcome? A precisely modeled nut, complete with threads, chamfers, and all the geometric complexities required by its real-world counterpart.

What’s truly mind-blowing here is the process. The journey wasn’t a straight line; it was a series of deliberate steps, each building upon the last, like a sculptor chipping away at stone. The developer meticulously documented the evolution, writing code in six stages, and crucially, generating visual outputs at every turn. A PNG of a four-view layout and a STEP file were created with each cargo run. This immediate feedback loop—seeing the digital representation solidify—is the kind of workflow that transforms abstract programming into tangible design.

Every step wrote out a PNG (4-view layout) and a STEP file when I ran cargo run, so dimension mistakes and shape glitches showed up right away.

This iterative refinement, catching errors instantly, is the bedrock of good engineering, digital or physical. It’s the difference between guessing and knowing.

The Nuts and Bolts of Rust CAD

The setup is straightforward enough for anyone familiar with Rust. The Cargo.toml file lists cadrum as a dependency.

[package]
name = "nut"
version = "0.1.0"
edition = "2021"
[dependencies]
cadrum = "0.8.1"

It’s worth noting that cadrum pulls in OpenCASCADE at build time. For Windows users, that first build might feel like waiting for paint to dry (or for a complex CAD kernel to compile). But subsequent runs? Lightning fast, thanks to caching. This initial hurdle is a small price to pay for the power unlocked.

We start simple: a cube. This initial step is pure validation, ensuring the code actually produces geometry.

```rust use cadrum::Solid; fn main() -> Result<()


🧬 Related Insights

Sam O'Brien
Written by

Programming language and ecosystem reporter. Tracks releases, package managers, and developer community shifts.

Worth sharing?

Get the best Developer Tools stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from DevTools Feed, delivered once a week.