Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 397 Bytes

File metadata and controls

33 lines (24 loc) · 397 Bytes

Traits & Bounds Cheatsheet

Syntaxe de Base

trait NomTrait {
    fn methode(&self);
}

impl NomTrait for Type {
    fn methode(&self) {
        // Implémentation
    }
}

Trait Bounds

fn fonction<T: Trait1 + Trait2>(x: T) { }

fn fonction2<T>(x: T) 
where
    T: Trait1 + Trait2,
{ }

Trait Objects

let obj: Box<dyn Trait> = Box::new(instance);