I find that I need to convert Option<String> to Option<&str> quite often. Simple option.as_ref() is not sufficient, because it gives Option<&String> which doesn't automagically deref.
The code for this is not terrible, but relatively long for an operation that seems basic: option.as_ref().map(|s| s.as_str()).
Could there be a better method for this? What would it be?
The most straightforward solution could be adding option.as_str() for Option<String>. I wouldn’t mind that, but it’s not generic (e.g. Option<Vec<T>> to Option<[T]> is left out).
However, I worry that more generic solutions would end up being blocked by either lack of specialization, or an overly generic as_ref() could risk breaking crates due to adding more ambiguity to type inference.