Using where

If you're used to programming using generics in C#, this should be familiar to you.

Rust contains an implementation of where, so we are able to define what where is. This means that, as we had in an earlier example for this chapter, the construct <T: Mul<Output = T>> can be used in a modified way:

impl<T> Calculate<T> for Shape<T> where T: Mul<Output = T>

This does, though, give rise to a number of other issues. Two simple ones are that we multiply by 2—however, that value isn't clear if it's 2u8 or 2i32. We also try to add values together, but as with multiplying T together, there is no guarantee you can add by T.

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

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