I have two issues I don't know how to solve though.
The first is how I can return a string ref without creating a temporary with to_string()
and how can I return an Err if the match does not succeed as I would have different types in different arms on the match ?
Returning a string ref from this function isn’t going to be possible(1). The reference would need to point into i somewhere, but the string you want to return, "2020-08-13" doesn’t appear as a substring of i ("today")— You’ll need to make the return type be a String instead of an &str.
Footnotes
(1) Not entirely true, there’s always a way. Here, you could use Box::leak, but it’s a bad idea. You get unbounded memory usage for almost no benefit.
As far as returning an error, if you want the closure to be fallible, use map_res instead of map. If you just need to include an _ arm to make the compiler happy since you're already handling all the variants, you can use _ => unreachable!() which will panic if its reached.