I hope you enjoyed that assignment and that you were able to successfully complete it.
We will now go over my solution for the assignment.
So the first thing that I want to do is create my struct.
So we'll say pub struck editor mute.
We need to pass in a lifetime.
And in here we will say next option.
And since we are going to have a reference, we need to specify our lifetime, which is why we gave
it at the up here with the struct note rt and now our struct is good.
So now we can come back down here.
We know that we need to pass an immutable reference to our self and our return type.
It's going to be an inner reboot of type T.
And what we will do here is we will return and enter mute where our next value is.
Self.
Dot head.
But instead of as DX reference as dx ref, we do as dx ref mute.
And that's the only difference between our iterator here and our mutable iterator.
We just needed to use as DX reference mutable versus as DX reference.
So now we can come down here and we can do our implementation block
on our iterator for editor Mute.
And as you might be guessing, it is going to be very similar to what we did up here.
So we can actually take this code, we can copy and paste it.
And what we're going to change in here is we'll make this as DX reference mute and we will also make
our type item mutable as well.
So we see that we have an error.
What do we have?
Mismatch types expected option and mute found option and T and that is because we need to make our return
type mutable as well.
So now that we have our attribute implemented in, we need to test it out to make sure that it works
properly.
So we would call our test function it or mute.
We will give it the test attribute and now we will say let mutable list equals list new list dot push.
We will push in three values again
and we will push in our normal one, two and three.
Now we will create our mutable iterator using list, dot it or mute and we will assert equals that enter
next.
Returns some and mute three because we expect our values to be returned as a mutable reference.
So if we execute this two more times, we would expect our next value to be a mutable two and a mutable
one.
So now if we run our test, we see that all four of our tests are passing, so our implementation for
attribute is working correctly.
So hopefully you were able to get this assignment.
If you have any questions, please feel free to ask me in the Q&A section and I will see you in the
next lecture.