1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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
    }
}