In the "parse_opts()" function, we are using a "match" statement to determine which image, if any, was specified on the command-line, and that information is put into the "kind" variable. We could create a new function that takes that "kind" variable and selects the appropriate image constant to manipulate. The problem with that is that now we'd have two match statements, and if a future ASCII-artist wanted to add a new image, say, of a bicyclist, he would have to make appropriate modifications to two match statements instead of just one. That both increases the possibility of human error, and makes debugging somewhat more difficult, not to mention that it's more work for the ASCII-artist.
So it'd probably be better to use the already-existing match statement. Let's go that route. Rather than having the match return just the kind, we'll have it return the kind and the image string itself, combining them as a tuple (remember, a tuple has nothing to do with "two"; the fact that there are two items in this tuple is just a coincidence; also, remember, a tuple is simply a variable holding a collection of variables; a grocery sack containing grocery sacks, so to speak). And then the overall "parse_opts()" function will add this new variable "image' from the match statement's returned tuple to its own tuple which it returns. Since we don't yet have the other images prepared in their own constants, but each arm of the match statement needs to return the same sort[s] of variable[s] as what the other arms return, we'll just temporarily plug in the "D51" constant as the second tuple item on all the match arms, just while we're developing things. Later we'll use a "C51" constant for the C51 image, and a "JACK" constant for the Jumping Jack image, and etc.
Since we'll be referencing the D51 constant, which is in the "d51.rs" file, we'll need to specify the path to that constant when we make that reference in "parse_opts()". We can do that in one of two ways: when we make the reference, we can specify the path at that point, as in "D" | "D51" =>
, or we could put a "use" statement at the top of the "parsing.rs" file. Let's go that latter route:
And now we can make the necessary changes to the "parse_opts()" function. Notice that since we haven't yet prepared the other images, but we need the output of the match arms to be consistent, we're temporarily using "D51" for all the matches. We'll fix that as we go.
Now in our "main()" function, instead of displaying the "D51" constant, we can display the "image_string" variable, which has been set to the "D51" constant by the match statement in "parse_opts()", according to what was entered on the command-line.
Verify that this code works, and then let's Add The C51, Little, and Jack Images.