Rust in 2019

Rust made good progress in 2018:

  • const fn in particular was a welcome and sorely needed feature.
  • With #[panic_handler] now stable, we can finally write no_std binary crates on stable and not worry the next release will break it.
  • We got some other useful features, including the following: u128, NonNull, fixed-length slice patterns, LTO, #[repr(transparent)], #[repr(align(_))]

In 2019, i have one major wish for Rust:
Const Generics.

The worst pain point for me, by far, is the inability to quantify over numbers. Notions as basic as an array of a CloneEq type being CloneEq are inexpressible in Rust now; see the ridiculous (and necessarily incomplete) list of impls for [_; _]. (Edit(2018-12-23): I see Clone is now magical. The infelicity remains for other traits such as Eq and Ord.) We have kludges like “typenum” and “generic-array“, but consider the impl header for matrix multiplication in my matrix library: impl<B: Copy, A: Copy + Mul<B>, K: ArrayLength<B> + ArrayLength<GenericArray<A, M>>, M: ArrayLength<A> + ArrayLength<A::Output>, N: ArrayLength<GenericArray<A::Output, M>> + ArrayLength<GenericArray<B, K>>> Mul<Matrix<B, K, N>> for Matrix<A, M, K> where A::Output: Zero + AddAssign Writing all the ArrayLength constraints is very tedious, and they are mere noise to a reader.

But the pain is deeper yet: these types are often part of the API, which makes me hesitate to stabilize such an API before we have const generics. (It also affects APIs which want to accept buffer sizes, for example.)

I hope at some point Rust will have a much richer kind system, letting users quantify over type constructors, arrays of types, and traits, at least. (See, for example, the broad utility of Monad :: (Type → Type) → Constraint in Haskell.) But the most urgently needed is natural numbers.

Note(2018-12-27): I posted a follow-up.

2 thoughts on “Rust in 2019”

  1. I absolutely agree that const generics are one of the most important features to land. Followed closely by specialization.

    BTW, the dark blue links on a black background is almost impossible to read on an AMOLED screen.

Leave a Reply

Your email address will not be published. Required fields are marked *