impl<T: Display> Display for Option<T>?


#1

At the moment, impl<T: Debug> Debug for Option<T> exists, but impl<T: Display> Display for Option<T> doesn’t. Would it make sense to implement that?

The natural thing to do is:

  • in the Some case, just call the Display impl on T
  • in the None case it wouldn’t display anything

Users would be free to override this by using a newtype wrapper (that’s what they have to do today anyway).


#2

Generally it seems that std doesn’t define Display for things where there are multiple reasonable choices, which is fairly often since humans are complicated :wink:

For the specific proposal given, it seems unfortunate that Some("").to_string() and None.to_string() would produce the same thing. And the best way to solve that seems like it’s context-specific, at which point not having the impl is just as good.