Rust supports a number of type coercions, which implicitly convert one type to another. As in any
language with coercion, there is a trade-off made between clarity when reading and ease of writing. While
disagreement may be had about whether Rust’s list of supported coercions is best, there is value in learning
the coercions available, as some are central to functioning or idiomatic Rust code. In this post, I describe
what coercions are possible, and where they can happen.
Jul 6th, 2021
· Guide
· #types
· By Andrew Lilley Brinker
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
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
Rust functions are surprisingly diverse, sitting at the intersection of multiple
language features which may take time to understand. In this post, we’ll walk through
those features and explain how they appear in function signatures, so you can be
well-equipped to understand functions you see in the wild, or identify the best way
to write the functions you need in your own code.
Jan 26th, 2021
· Guide
· #functions
· By Andrew Lilley Brinker
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