We can pass traits as parameters as well.
In the earlier examples, we implemented the trait overview for both course and another course.
So let's create a function that's going to call the overview method from its item parameter.
So the first thing we need to do is create that function.
We're going to give it the item parameter that's going to have a reference to the overview implementation.
And then in here we're just going to print out overview
and then item dot overview.
So since we already have these two types created that implement the overview method, we can call them.
So we'll call course one.
And of course we need to pass it by reference and then we can also do this for course to.
So we run it and we see this is a rust course, which is of course one and also the default implementation.
And then we have our modified course, which is another tiler, another headline.
So awesome.
So that's working good.
But we can actually simplify the function and what we can do is come in here and say a type of overview.
And then we can just change all of this right here.
Did you say a reference to type?
And it's the same exact thing.
So.
The first way we did it is convenient and makes for more concise code and simple cases, whereas what
we have implemented now can express more complexity.
A little bit more clearly.
Also the.
Replacement Station overview works for straightforward cases.
So what I'm referring to now is what we did in the earlier case.
So let me go back to that.
So the implement overview.
Get rid of the air.
The implement overview works for straightforward cases, but is actually just shorthand for a trait
bounce.
So let's look at some different trait patterns and I'm just going to have all these commented in that
way.
We can just kind of see everything side by side.
So the first one is going to be if we had the overview function, we had item one and it was.
You know, implementing in the overview trait.
And then item two also implements
the overview trait.
So this allows item one and item two to be of different types, but we can force them to be of the same
type if we want it to.
And that's where the method that we just had comes into play.
So we can say overview again, but this time t of overview.
And now it's going to be item one and T and then item to A and T as well.
So again, these are the same thing, but this one can have different types.
And this one, we are making them have to be the same type.
And then the last thing we can do is we can have multiple trade bounds and this is done
this way.
So we created our function again.
We're passing in item one and we're going to implement an overview.
And then plus and then our other trait.
So plus another trait allows us to have multiple trait bounds.
And then just to keep everything uniform.
If we wanted to see this in the other way, it would be t.
Overview plus another trait.
And then we have item one.
Anti item to.
Anti and that's going to make them have to be of the same type.
So with all of that, I just wanted to show you some extra functionality we can use traits for and I
hope it all make sense.
I know we've learned a lot about genetics and traits so far in this section, so just take a second
to make sure you fully understand everything before continuing on to the next lecture where we will
start talking about utility traits.