Until now, we have only been talking about other people’s traits. But we can also define our own traits.Imagine that we want to estimate reading time. It shouldn’t matter what type of content we are reading (an article, a novel, or even a poem). We could use the following trait:// [1]
trait Estimatable {
// [2] [3]
fn estimate(&self) -> f64;
}
// [1]: The trait name (in this case, Estimatable).
// [2]: Trait methods (in this case, only one).
// [3]: The **&self** parameter, followed by other parameters (in this case, none)
Note: We are using a simple type for minutes for the sake of simplicity. Try not to do this at home! And try not to do this in production!Any type implementing the Estimatable trait should define an estimate method that calculates how long it might take to read something in minutes.Let’s try doing that.