Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sorted-trait-items

Level: warn · Fixed by rabot fmt · Article: Sorting

What it checks

Items in a trait definition: associated consts, then associated types, then functions, each group alphabetical. Trait impls follow the same order (see sorted-impl-items), so a definition and its impls line up.

Don’t

#![allow(unused)]
fn main() {
trait Persist {
    fn save(&self, store: &Store) -> Result<(), SaveError>;
    type Error;
    fn load(id: &Id, store: &Store) -> Result<Self, Self::Error>;
    const TABLE: &'static str;
}
}

Do

#![allow(unused)]
fn main() {
trait Persist {
    const TABLE: &'static str;
    type Error;
    fn load(id: &Id, store: &Store) -> Result<Self, Self::Error>;
    fn save(&self, store: &Store) -> Result<(), SaveError>;
}
}

Silence it

#![allow(unused)]
fn main() {
// rabot: allow(sorted-trait-items) documented as a state machine: methods appear in call order
trait Handshake { .. }
}