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

Traits

Rust-like traits.

Design

Definition

trait Foo {
fn bar() uint;

fn baz() {
// snip
}
}

Implementation

struct MyType;

impl Foo for MyType {
// notice how there is no type in impl block
//
// concern: against code locality
fn bar() {
// chosen by a fair roll of dice
4
}
}