0Pricing
Learn Rust Coding · Lesson

where Clauses and Multiple Bounds

Keep complex signatures readable.

When Inline Bounds Get Crowded

Inline bounds like <T: Display + Clone, U: Debug + Default> become hard to read as they grow. Rust offers the where clause as a cleaner alternative.

It moves the constraints below the signature, keeping the parameter list short.

Basic where Clause

A where clause sits between the return type and the body. Each line lists a type and its bounds.

These two signatures mean exactly the same thing; the where form just reads better.

use std::fmt::Display;

fn show<T>(value: T)
where
    T: Display,
{
    println!("{}", value);
}

All lessons in this course

  1. Generic Functions
  2. Generic Structs and Enums
  3. Trait Bounds
  4. where Clauses and Multiple Bounds
← Back to Learn Rust Coding