fmt::Display for T, E => fmt::Display for Result?

#1
  1. If I am reading the docs correctly, there is no “impl fmt::Display for Result”

  2. Given that both Result and fmt::Display are part of Rust’s standard library, is there anyway to do:

If we have fmt::Display for T, E ... then we get fmt::Display for Result<T, E>

0 Likes

#2

Just out of curiosity, why the need to use Display with something like this, when you can just use Debug? Option and Result really don’t have any reason to implement Display because how it’s displayed is up to the user (Whether it mentions a None value for example)

1 Like

#3

Hi, you can do this, it mimics the Debug version, but you can change the writes to make them behave like you want.

1 Like

#4

@OptimisticPeach : I don’t have a good answer to this. I (perhaps incorrectly) throught Debut was meant just for debugging, and Display is meant for regular console output.

0 Likes

#5

Well, Debug is preferred for debugging, and (If I recall correctly) is implemented for all types under std. The only difference is that Debug is meant to just output the data, and get it out there, while

Display is for user-facing output

So, using Debug on things will usually work, as it’s not every day that you’re Displaying a ToLowercase to the user :smile:

0 Likes

#6

We don’t have that for the same kind of reason we don’t have Option<T: Display>: Display:

1 Like