You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to be able to print strings directly without converting them to a String, thereby avoiding the allocation.
While trying to implement this locally, I noticed that implementing Display automatically implies a ToString implementation, which conflicts with the current to_string functions as they return an error when encountering invalid code units, whereas my Display implementation performs the conversion lossily. Therefore, implementing Display would be a breaking change.
Solutions I could think of:
Rename the conversion methods Pro: makes displaying strings convenient Con: breaks the API and does not follow the naming guidelines
Add a display method similar to Path::display Pro: allows configuring different replacement options, like escaping invalid units Con: is not as straightforward and complicates usage when using proc-macros like thiserror
The text was updated successfully, but these errors were encountered:
I agree that having a Display impl would be very useful.
I also think the default Debug impl should be swapped out for something more similar to the regular String debug implementation, instead of printing the underlying Vec as raw bytes.
I've added display method to the strings. The new Display object by default does a replacement character for invalid values, with an {:#} alternate formatting option that entirely skips invalid values when printing. If you have better ideas for the alternate formatting, let me know, I couldn't think of anything else particularly useful off the top of my head.
I've also improved the Debug implementations. They now do standard escape_debug style strings on valid UTF data, just like std strings, but invalid values are displayed as \<XXXX> (XXXX being hex value), an intentionally invalid escape sequence that makes it relatively easy to see the raw invalid values.
It would be useful to be able to print strings directly without converting them to a String, thereby avoiding the allocation.
While trying to implement this locally, I noticed that implementing
Display
automatically implies aToString
implementation, which conflicts with the currentto_string
functions as they return an error when encountering invalid code units, whereas myDisplay
implementation performs the conversion lossily. Therefore, implementingDisplay
would be a breaking change.Solutions I could think of:
Pro: makes displaying strings convenient
Con: breaks the API and does not follow the naming guidelines
display
method similar toPath::display
Pro: allows configuring different replacement options, like escaping invalid units
Con: is not as straightforward and complicates usage when using proc-macros like
thiserror
The text was updated successfully, but these errors were encountered: