The next step we want to do is to remove the quotes and to convert the single &str into a vector of String vectors, each inner String vector holding a single frame of the image. So if the image has six frames, we'll have six inner String vectors in the outer vector. Let's put these tasks in their own function, which will return a vector containing String vectors.
We need to figure out where to put our function. Since we moved the image constants to "images.rs", we no longer need the "d51.rs", "c51.rs", or "little.rs", if any of those are still around; I'm going to delete mine.
That leaves us with "main.rs", "images.rs", "parsing.rs", and "drawing.rs". We could create a new module file for our new function, or we could add it to one of our existing functions.
We could put the functionality in "parse_opts()", or at least the function in "parsing.rs"; after all, it could be argued that the purpose of "parse_opts" is to return the user's choice of image, and that an incomplete image leaves that job unfinished. On the other hand, processing the user's input is really a different task than is simply getting an input choice from the user. On the third hand, we've already processed the choice to some extent, converting "kind" to 'image".
We could put the function[ality] in "drawing.rs", arguing that prepping the image is part of drawing it. On the other hand, prepping the image is a separate task from drawing the image.
We could put the function in a new file, but that just adds to the clutter of files and "mod" and "use" statements.
We could put the function[ality] in "main.rs", but we said from the beginning we didn't want to clutter up that file.
None of these solutions are "wrong"; it's simply a design-choice. I think I'll go with the first option of putting the new function in "parsing.rs", but I'll rename "parsing.rs" to something less specific than only parsing command-line arguments, to something like "get_options.rs".
Renaming "parsing.rs" to "get_options.rs" also means we need to update the "mod" and "use" lines in "main.rs":
Now let's create our function:
The first thing we'll want the new function to do is to remove the single-quotes.
We can simply remove the single-quotes, or we can replace them with spaces. If we replace them with spaces, then we won't have to worry about leaving behind a trail of image bits as the image moves across the screen, particularly in "Fly" mode, because the trailing space will overwrite any pieces that might otherwise get left behind. The only "cost" associated with doing this is that the image will have to travel two extra columns worth of space as it goes across the screen, which means the user might be looking at an extra few milliseconds of empty screen at the very first or the very last of the trip across the screen. That's a very reasonable extra cost to make sure that we don't have image bits left behind. Therefore, let's replace those single-quotes with spaces instead of simply removing them. This is a one-liner:
Well, that was easy. But let's test it. Temporarily, make the following changes:
This should compile and run exactly as before our changes, except that the single-quotes are no longer shown in the display of the images.
Now to convert the several frames of the one string into several string elements in a vector.
And now...
Test, and all should be working.
Now it's time to Animate the Image Across the Screen.