Specialization of `impl ToString for Box<str>`?

If the standard library wasn’t split between core and alloc, then ToString wouldn’t need to exist and a to_string method could be part of Display, which could be overridden without the need for any specialization. Display for Box<T> could just call the to_string method from Display for T, so Box<str> would be properly optimized as desired. But alas, Display lives in core and String & ToString live in alloc.

I feel there’s some kind of language design opportunity that could make this possible despite of the split.

And/or clever library design. E.g. this thread earlier this year tried finding a library solution:

1 Like