16 Const, “unsafe” Rust, and external crates

This chapter covers

  • Const generics, or generics over const values
  • Const functions that you can always call at compile time
  • Mutable statics, the unsafe way to change static variables
  • Unsafe Rust
  • External crates, including rand

It’s now time to learn about Rust’s third generic type (const generics) and all the other things to do with const and static in Rust. Const generics let you be generic over const values, which is most useful when working with arrays. Const functions are similar to regular functions, but they can be called at compile time before your program starts. We will also start to learn about the unsafe side of Rust, starting with static mut, a static that is unsafe to use. We’ll also ...

Get Learn Rust in a Month of Lunches now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.