Defining the impl for specific types

This is by far the simplest way of creating the code. We define the types that Shape can take:

impl Calculate<i32> for Shape<i32> 
{
fn calc(&self) -> i32
{
self.line_one * 2 + self.line_two * 2
}
}

Writing the code like this ensures that we cannot pass anything into the implementations that don't make any sense (for example, types that cannot have + or * applied to them).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset