1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
pub mod mod_trait { pub struct StructType { pub data: u32, } // Defining a trait for any type pub trait CanalTrait { fn foo(&self) -> u32; } // Implementing a trait for a type impl CanalTrait for StructType { fn foo(&self) -> u32 { self.data } } } pub mod mod_bare { pub struct StructType { pub data: u32, } impl StructType { pub fn foo(&self) -> u32 { self.data } } }