1 00:00:06,310 --> 00:00:10,570 I hope you enjoyed that assignment and that you were able to successfully complete it. 2 00:00:10,750 --> 00:00:14,080 We will now go over my solution for the assignment. 3 00:00:14,350 --> 00:00:18,910 So the first thing that I want to do is create my struct. 4 00:00:19,300 --> 00:00:23,440 So we'll say pub struck editor mute. 5 00:00:25,150 --> 00:00:27,040 We need to pass in a lifetime. 6 00:00:28,810 --> 00:00:32,710 And in here we will say next option. 7 00:00:33,250 --> 00:00:39,100 And since we are going to have a reference, we need to specify our lifetime, which is why we gave 8 00:00:39,100 --> 00:00:47,560 it at the up here with the struct note rt and now our struct is good. 9 00:00:48,840 --> 00:00:50,400 So now we can come back down here. 10 00:00:50,610 --> 00:00:56,400 We know that we need to pass an immutable reference to our self and our return type. 11 00:00:56,430 --> 00:01:01,380 It's going to be an inner reboot of type T. 12 00:01:04,450 --> 00:01:11,350 And what we will do here is we will return and enter mute where our next value is. 13 00:01:11,350 --> 00:01:12,070 Self. 14 00:01:12,370 --> 00:01:13,540 Dot head. 15 00:01:15,280 --> 00:01:20,590 But instead of as DX reference as dx ref, we do as dx ref mute. 16 00:01:21,460 --> 00:01:28,180 And that's the only difference between our iterator here and our mutable iterator. 17 00:01:28,300 --> 00:01:33,670 We just needed to use as DX reference mutable versus as DX reference. 18 00:01:34,090 --> 00:01:39,370 So now we can come down here and we can do our implementation block 19 00:01:41,950 --> 00:01:46,210 on our iterator for editor Mute. 20 00:01:46,690 --> 00:01:54,490 And as you might be guessing, it is going to be very similar to what we did up here. 21 00:01:54,490 --> 00:01:58,480 So we can actually take this code, we can copy and paste it. 22 00:01:58,930 --> 00:02:10,240 And what we're going to change in here is we'll make this as DX reference mute and we will also make 23 00:02:10,240 --> 00:02:14,470 our type item mutable as well. 24 00:02:16,390 --> 00:02:18,170 So we see that we have an error. 25 00:02:18,190 --> 00:02:19,440 What do we have? 26 00:02:19,450 --> 00:02:30,550 Mismatch types expected option and mute found option and T and that is because we need to make our return 27 00:02:30,550 --> 00:02:33,640 type mutable as well. 28 00:02:34,480 --> 00:02:42,190 So now that we have our attribute implemented in, we need to test it out to make sure that it works 29 00:02:42,190 --> 00:02:42,940 properly. 30 00:02:47,780 --> 00:02:50,660 So we would call our test function it or mute. 31 00:02:52,520 --> 00:03:06,230 We will give it the test attribute and now we will say let mutable list equals list new list dot push. 32 00:03:08,090 --> 00:03:11,000 We will push in three values again 33 00:03:13,700 --> 00:03:17,570 and we will push in our normal one, two and three. 34 00:03:19,430 --> 00:03:34,010 Now we will create our mutable iterator using list, dot it or mute and we will assert equals that enter 35 00:03:35,360 --> 00:03:36,290 next. 36 00:03:38,530 --> 00:03:48,070 Returns some and mute three because we expect our values to be returned as a mutable reference. 37 00:03:48,310 --> 00:03:58,780 So if we execute this two more times, we would expect our next value to be a mutable two and a mutable 38 00:03:58,900 --> 00:03:59,680 one. 39 00:04:00,160 --> 00:04:08,590 So now if we run our test, we see that all four of our tests are passing, so our implementation for 40 00:04:08,590 --> 00:04:11,200 attribute is working correctly. 41 00:04:11,320 --> 00:04:14,110 So hopefully you were able to get this assignment. 42 00:04:14,260 --> 00:04:20,320 If you have any questions, please feel free to ask me in the Q&A section and I will see you in the 43 00:04:20,320 --> 00:04:21,220 next lecture.