-
Notifications
You must be signed in to change notification settings - Fork 32
Description
From the docs:
fn width<'a>(&'a self) -> usize
Returns the string's displayed width in columns.
Control characters are treated as having zero width.
(Ignore '\0' for the points below as it has special treatment.)
This seems inconsistent with the behaviour for individual char
s, where None
is returned in case you have a control character. For consistency, I would expect (A) for a string, if any character has a width of None
, the result should have width None
XOR (B) control characters always have width Some(0)
.
IIUC, the second option hasn't been taken for consistency with wcwidth
, which returns -1
for control characters. However, not taking the first option can lead to non-intuitive behaviour that can go by unnoticed.
E.g. if the code has LF/TAB/DEL in it, then you can get an answer that doesn't make much sense.
Moreover, this violates an embedding law that one might expect to hold: width(format!("{}", c)) == width(c)
(because it doesn't even type-check).
What is the reasoning behind the current behaviour?
P.S. I'm not asking for the library's behaviour to be changed. I'm writing a Haskell implementation and ran into this while looking at the test cases. My library follows (A) because it seemed like the right choice, so I wanted to know why you didn't pick (A).