Scrapmetal — Scrap Your Rust Boilerplate


#1

http://fitzgeraldnick.com/2017/08/03/scrapmetal.html

TLDR: I translated some of the code and ideas from Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming by Lämmel and Peyton Jones to Rust and it’s available as the scrapmetal crate.


#2

Interesting read.

The article reminds me of a problem that had to be solved in the gltf crate, namely checking the bounds of all indices in a complex data structure. It’s seemed like a simple problem to solve, but making sure no index was left unchecked was difficult.

The solution used a Validate trait plus a procedural macro that generated the code to propagate down the data structures. All that was necessary was to wrap the indices in an Index type, implement Validate on Index and voilà, the compiler would guarantee that each and every index would be checked.