Okay.
So we're receiving our args here and we're placing them inside a vector string.
So let's create a new function called pass args.
And inside here, we want to return some arguments.
So let's actually take this logic out of run.
Place it inside of here.
And now in here we'll just call Pass ARGs.
And now that we're looking to return a argument struck.
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
want to clone it.
That way we get a copy of it and then we want to do the same thing for the rest of our field.
So we'll have input file.
It's going to be args of two.
And lastly, our output file is going to be a large three dot clone.
So now we're getting.
All of this printed out.
So let's actually just make sure that what we get is correct.
So let's, let's print out our args right here.
Go.
You there.
And I will say, art.
So if we run this.
It helps if I had an hour one, two, three and four.
We see that our pattern was assigned to one.
Replace our two.
Input AAC three, output AAC four.
So everything there looks correct.
So we know that we're handling and assigning our arguments into the arguments array properly.
So now we'll actually keep it that way.
So we'll say let args equals parse args.
So now we need to handle how we get the data to and from the file system.
So we have done a little bit of this before.
So we already know that the designers of the standard library made this pretty easy for us to do.
We do need to import in the standard file system and this is going to let us gain access to the methods
that we require.
So now we can create a read and write function which is going to accept a reference to our arguments
struct that we just created.
And we're not going to return anything.
But now we're going to say let data match and then the RFS file system read to string and we see that
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
to be our args.
Input file.
So now that we know that we also returned in or we're getting returned a result, we need to make sure
we handle the errors in case that we get any.
So if we're returned and OC awesome, we want that the result inside of the OC to be assigned to data.
Otherwise if we get an error, then we need to handle the error.
So we're going to print out.
Failed to read from file and then we'll print out our file name.
And now we're also going to want to print out our Air Force.
So we'll do again what we did earlier, air, dot red, dot bold, and then we want to print out our
args dot input file name.
And then we also want to print out the air.
And as we did earlier, we want to make sure that we exit the process with an error code of with an
exit code of one to signify that, hey, it was not a successful completion.
And then we also want to match on writing because we are eventually going to have to replace the strings
in our file with our desired replacement string.
So in here we're going to have our args output file.
And then we're also going to need the data which in this case, what we're going to do is just to get
this logic wired up.
We're just going to basically copy the cargo.
Will file and then just output it to a.
Poppycock.
Tom will file just to make sure that our reading and writing logic is being done correctly.
So in this case, we do not care what the result is going to return.
But we do care if we get an error.
And I need to correct that.
And again, like what we did earlier.
Instead of it being reading, it's going to be writing.
Failed to write to file error.
And then we'll have output file and then we'll also have our error message there.
Awesome.
So all of that should be good.
We'll call, read and write and then we'll pass in a reference to our arguments.
So just to make sure our error logic still works, we call cargo run with no arguments.
We see that our error messages are printed out successfully.
So now in this case, we will say cargo run.
Ah, one or two because we don't necessarily care about those yet, because that will be what our Reg
X is looking at.
And now we want to do cargo Tamil to copy Tamil.
Okay.
So it ran successfully and we see that we were generated a copy Tamil file.
So if we look at.
Our cargo.
That's what we see.
And then inside of here, we see that they are the exact same thing.
So with this, we were able to verify that our reading and writing to file logic is being done correctly.
So now the next step is going to be to find some strings and a text and then replace it with a new desired
string, which we will do.
And the next lecture.