1 00:00:05,690 --> 00:00:12,200 So again, we could very easily keep everything in mind because this will be a small program. 2 00:00:12,200 --> 00:00:18,500 But let's take a quick minute to implement good practice and place our code in another file and then 3 00:00:18,500 --> 00:00:19,850 we will just have main. 4 00:00:20,620 --> 00:00:21,670 All that code. 5 00:00:21,940 --> 00:00:29,320 So let's create a new file inside of source called Find and Replace. 6 00:00:32,460 --> 00:00:37,260 And in here is where we can store all of our logic. 7 00:00:38,190 --> 00:00:40,470 So let's take all of this. 8 00:00:41,310 --> 00:00:49,890 Cut it out here, paste it in here, and then let's take this function, cut it out of here, and also 9 00:00:50,280 --> 00:00:51,360 put it in here. 10 00:00:51,570 --> 00:01:00,510 And then we're going to create a public function called run, which is where we can take all of our 11 00:01:00,990 --> 00:01:05,280 logic inside of main take it out and. 12 00:01:06,280 --> 00:01:08,020 Place it inside of here. 13 00:01:08,620 --> 00:01:15,610 So now we can come into main address and say mod find and replace. 14 00:01:16,180 --> 00:01:19,810 And now we can just say find and replace. 15 00:01:20,350 --> 00:01:20,860 Run. 16 00:01:22,760 --> 00:01:25,490 And it's able to find it because run is public. 17 00:01:25,580 --> 00:01:27,370 So all of that is good. 18 00:01:27,380 --> 00:01:34,160 But now let's just make sure before we try running this, let's look at our our tree. 19 00:01:34,160 --> 00:01:40,130 So remember, we can use cargo modules, generate tree, and then I want to generate mine with types 20 00:01:40,130 --> 00:01:41,630 that I can see everything. 21 00:01:43,910 --> 00:01:47,840 So we see we have our find and replace module. 22 00:01:47,870 --> 00:01:49,610 We have our stuck in here private. 23 00:01:49,610 --> 00:01:53,540 Great our print help function is private perfect. 24 00:01:53,540 --> 00:01:59,000 And now our run function is public, which we then call inside of main. 25 00:01:59,000 --> 00:02:00,260 So everything looks good. 26 00:02:00,260 --> 00:02:02,120 So now let's run it. 27 00:02:02,120 --> 00:02:04,400 Make sure our error message is is printed out. 28 00:02:05,440 --> 00:02:06,200 And they are. 29 00:02:06,220 --> 00:02:09,460 So now let's run it again with giving it four arguments. 30 00:02:09,700 --> 00:02:10,480 And perfect. 31 00:02:10,480 --> 00:02:18,280 So we're back at the same place we were prior to separating our code into a module. 32 00:02:18,640 --> 00:02:24,970 So now we're right back to where we were and now we can continue on with handling our file logic.