Open LeeNeu opened 1 week ago
Hi, I would like to take this issue. Basically you want to return an Option in the search function. How do you see the missing String to be handled? Would you like to return an Error or just an empty String?
Hi,
You can have it, I'll assign it to you. I think it would be best to handle the 'None' case in the 'exec_args' function. At this moment exec_args returns whatever string is found in the search function. I would like that when the 'search' function returns its Option type, the 'exec_args' function should match that type and when in case it is 'None' it should return a String in which it lets the user know that nothing was found e.g. "No matching String could be found in File".
Let me know if you have another solution for this.
I would suggest return an Error and define a custom Error type with thiserror crate. Then, the exec_args
would return Result<String, GrepError>
as well as the main function. This way, if the string is not found in the file, you would not print an error message with println, but return an actual error with return value of 1. What do you think?
I like the idea. This way we can also differentiate between multiple errors that can occur when searching the file later on. But also I would like to have a verbose error message for the user in the terminal. So when somebody uses the cli and the String he is searching for is not found he will get some kind of feedback printed that the String could not be found, instead of an Error value.
The search function in lib.rs should return an Option\<String> type instead of String. This will ensure that when no matching String can be found in the Haystack the missing String can be handled properly.