gear idea
Possible Rust

Learning what’s possible in Rust.
Jump to Navigation

CategoryPatterns


Naming Your Lifetimes

You may not know this, but it’s possible to give names to your lifetimes which are longer than a single character! Effectively naming your lifetimes can help improve code clarity in several scenarios, which this post describes in detail.

May 20th, 2021 · Pattern · #lifetimes · By Andrew Lilley Brinker

3 Things to Try When You Can't Make a Trait Object

Trait objects are Rust’s usual mechanism for dynamic dispatch, and when they work they’re wonderful, but many Rust programmers have struggled with the question of when a trait can become a trait object, and what to do when a trait they’re using can’t. This post describes several options for handling an inability to create a trait object, discusses their trade-offs, and describes why the trait object limitations exist in the first place, and what those limitations are exactly.

Feb 2nd, 2021 · Pattern · #trait objects · By Andrew Lilley Brinker

Non-Generic Inner Functions

Steve Klabnik recently wrote about whether out parameters are idiomatic in Rust. The post ends by showing a snippet of code: a generic function, with a non-generic function inside of it which contains the actual implementation. Steve says this pattern may warrant its own post, so here is that post, where I’ll explain why this inner function is useful, discuss the trade-offs of doing it, and describe why this pattern will hopefully not be necessary in the future.

Oct 20th, 2020 · Pattern · #generics · By Andrew Lilley Brinker

Rust Lints You May Not Know

The Rust compiler ships with a number of useful lints on by default, and many use Clippy to provide additional lints. It’s less well known that the Rust compiler ships with some useful lints which are set to allow by default, meaning they don’t generate warnings. In this post, I’ll explain what each of these lints does, and why it might be useful.

Jun 21st, 2020 · Pattern · #lints · By Andrew Lilley Brinker