1 00:00:05,950 --> 00:00:06,490 Okay. 2 00:00:06,490 --> 00:00:13,150 So we're receiving our args here and we're placing them inside a vector string. 3 00:00:13,150 --> 00:00:19,480 So let's create a new function called pass args. 4 00:00:20,920 --> 00:00:25,530 And inside here, we want to return some arguments. 5 00:00:25,570 --> 00:00:29,860 So let's actually take this logic out of run. 6 00:00:30,610 --> 00:00:32,440 Place it inside of here. 7 00:00:34,520 --> 00:00:38,180 And now in here we'll just call Pass ARGs. 8 00:00:38,270 --> 00:00:43,250 And now that we're looking to return a argument struck. 9 00:00:44,460 --> 00:00:55,440 What we'll do is we'll create it and we'll say our pattern is going to be args of zero and then we just 10 00:00:55,440 --> 00:00:57,210 want to clone it. 11 00:00:57,210 --> 00:01:08,250 That way we get a copy of it and then we want to do the same thing for the rest of our field. 12 00:01:08,260 --> 00:01:10,290 So we'll have input file. 13 00:01:10,800 --> 00:01:12,900 It's going to be args of two. 14 00:01:15,150 --> 00:01:22,830 And lastly, our output file is going to be a large three dot clone. 15 00:01:23,940 --> 00:01:25,380 So now we're getting. 16 00:01:27,240 --> 00:01:28,320 All of this printed out. 17 00:01:28,320 --> 00:01:34,380 So let's actually just make sure that what we get is correct. 18 00:01:34,380 --> 00:01:39,270 So let's, let's print out our args right here. 19 00:01:45,670 --> 00:01:46,090 Go. 20 00:01:48,150 --> 00:01:50,190 You there. 21 00:01:50,910 --> 00:01:52,570 And I will say, art. 22 00:01:52,590 --> 00:01:54,330 So if we run this. 23 00:01:56,900 --> 00:02:02,230 It helps if I had an hour one, two, three and four. 24 00:02:02,260 --> 00:02:04,960 We see that our pattern was assigned to one. 25 00:02:04,960 --> 00:02:06,520 Replace our two. 26 00:02:08,340 --> 00:02:10,500 Input AAC three, output AAC four. 27 00:02:10,500 --> 00:02:13,590 So everything there looks correct. 28 00:02:13,590 --> 00:02:19,980 So we know that we're handling and assigning our arguments into the arguments array properly. 29 00:02:21,310 --> 00:02:24,550 So now we'll actually keep it that way. 30 00:02:24,550 --> 00:02:28,290 So we'll say let args equals parse args. 31 00:02:28,300 --> 00:02:35,320 So now we need to handle how we get the data to and from the file system. 32 00:02:35,320 --> 00:02:37,990 So we have done a little bit of this before. 33 00:02:37,990 --> 00:02:44,620 So we already know that the designers of the standard library made this pretty easy for us to do. 34 00:02:45,600 --> 00:02:56,400 We do need to import in the standard file system and this is going to let us gain access to the methods 35 00:02:56,400 --> 00:02:57,690 that we require. 36 00:02:58,290 --> 00:03:07,860 So now we can create a read and write function which is going to accept a reference to our arguments 37 00:03:07,860 --> 00:03:09,720 struct that we just created. 38 00:03:10,440 --> 00:03:13,050 And we're not going to return anything. 39 00:03:13,050 --> 00:03:25,290 But now we're going to say let data match and then the RFS file system read to string and we see that 40 00:03:25,290 --> 00:03:33,420 it's going to return a result to us, but we need a path to what file we want to read in and it's going 41 00:03:33,420 --> 00:03:34,830 to be our args. 42 00:03:37,210 --> 00:03:38,180 Input file. 43 00:03:38,200 --> 00:03:44,380 So now that we know that we also returned in or we're getting returned a result, we need to make sure 44 00:03:44,380 --> 00:03:49,030 we handle the errors in case that we get any. 45 00:03:49,270 --> 00:03:58,960 So if we're returned and OC awesome, we want that the result inside of the OC to be assigned to data. 46 00:03:58,990 --> 00:04:04,210 Otherwise if we get an error, then we need to handle the error. 47 00:04:04,660 --> 00:04:09,160 So we're going to print out. 48 00:04:11,020 --> 00:04:17,320 Failed to read from file and then we'll print out our file name. 49 00:04:17,680 --> 00:04:21,100 And now we're also going to want to print out our Air Force. 50 00:04:22,690 --> 00:04:33,280 So we'll do again what we did earlier, air, dot red, dot bold, and then we want to print out our 51 00:04:33,280 --> 00:04:35,800 args dot input file name. 52 00:04:35,800 --> 00:04:38,140 And then we also want to print out the air. 53 00:04:39,970 --> 00:04:46,180 And as we did earlier, we want to make sure that we exit the process with an error code of with an 54 00:04:46,180 --> 00:04:51,130 exit code of one to signify that, hey, it was not a successful completion. 55 00:04:52,620 --> 00:05:00,660 And then we also want to match on writing because we are eventually going to have to replace the strings 56 00:05:02,130 --> 00:05:06,180 in our file with our desired replacement string. 57 00:05:06,420 --> 00:05:10,080 So in here we're going to have our args output file. 58 00:05:11,460 --> 00:05:17,700 And then we're also going to need the data which in this case, what we're going to do is just to get 59 00:05:17,700 --> 00:05:19,320 this logic wired up. 60 00:05:19,620 --> 00:05:22,590 We're just going to basically copy the cargo. 61 00:05:23,970 --> 00:05:27,000 Will file and then just output it to a. 62 00:05:28,350 --> 00:05:28,920 Poppycock. 63 00:05:28,950 --> 00:05:34,650 Tom will file just to make sure that our reading and writing logic is being done correctly. 64 00:05:35,250 --> 00:05:40,080 So in this case, we do not care what the result is going to return. 65 00:05:41,100 --> 00:05:44,130 But we do care if we get an error. 66 00:05:46,130 --> 00:05:48,680 And I need to correct that. 67 00:05:50,720 --> 00:05:52,580 And again, like what we did earlier. 68 00:05:52,970 --> 00:05:56,300 Instead of it being reading, it's going to be writing. 69 00:05:56,300 --> 00:06:01,700 Failed to write to file error. 70 00:06:02,150 --> 00:06:06,770 And then we'll have output file and then we'll also have our error message there. 71 00:06:07,980 --> 00:06:08,400 Awesome. 72 00:06:08,400 --> 00:06:11,610 So all of that should be good. 73 00:06:11,910 --> 00:06:17,100 We'll call, read and write and then we'll pass in a reference to our arguments. 74 00:06:17,520 --> 00:06:23,550 So just to make sure our error logic still works, we call cargo run with no arguments. 75 00:06:23,580 --> 00:06:26,940 We see that our error messages are printed out successfully. 76 00:06:26,940 --> 00:06:31,950 So now in this case, we will say cargo run. 77 00:06:34,640 --> 00:06:41,050 Ah, one or two because we don't necessarily care about those yet, because that will be what our Reg 78 00:06:41,050 --> 00:06:42,280 X is looking at. 79 00:06:42,370 --> 00:06:49,000 And now we want to do cargo Tamil to copy Tamil. 80 00:06:50,820 --> 00:06:51,130 Okay. 81 00:06:51,210 --> 00:06:57,210 So it ran successfully and we see that we were generated a copy Tamil file. 82 00:06:57,810 --> 00:06:58,620 So if we look at. 83 00:06:59,260 --> 00:07:00,250 Our cargo. 84 00:07:00,250 --> 00:07:01,420 That's what we see. 85 00:07:01,420 --> 00:07:05,170 And then inside of here, we see that they are the exact same thing. 86 00:07:05,290 --> 00:07:13,660 So with this, we were able to verify that our reading and writing to file logic is being done correctly. 87 00:07:13,660 --> 00:07:22,780 So now the next step is going to be to find some strings and a text and then replace it with a new desired 88 00:07:22,780 --> 00:07:24,520 string, which we will do. 89 00:07:24,520 --> 00:07:25,570 And the next lecture.