Suppose I am writing a function that takes a bunch of string and filters out the "bad" ones.
The function then returns some strings, but there is a chance that all the strings are filtered out.
So I am wondering, should I use to Option here? I could see it making sense that the function either returns the None option variant when all strings are "bad", and it returns the Some variant when the strings are "good".
The function signature could look something like this:
pub fn filter_strings(inputs: Vec<String>) -> Option<Vec<String>> {
// Todo...
}
But is there really any point in making this an Option?
Would this just make things unnecessarily more complicated since the consumer kind of needs to now check for the None variant and also for the case where it returns Some empty vector?
Is it simpler and more "idiomatic Rust" to just return a vector of strings here?
pub fn filter_strings(inputs: Vec<String>) -> Vec<String> {
// Todo...
}
Or is there some advantage to using Option here that I am missing?