Reimpl cformat to suit for bytes#2318
Conversation
|
Fixes #2121 |
|
|
||
| #[derive(Debug, PartialEq)] | ||
| pub(crate) struct CFormatBytes { | ||
| parts: Vec<(usize, CFormatPart)>, |
There was a problem hiding this comment.
CFormatPart should probably be generic to allow String or Vec<u8>
There was a problem hiding this comment.
I'm not sure that is necessary, I am using String as Vec here for bytes. As String stores char as utf-8 so I don't think any cost here.
There was a problem hiding this comment.
@coolreader18 do you have an example which distinguish bytes and str for the case?
There was a problem hiding this comment.
Well bytes can have non-ascii and still be formatted, while a String wouldn't conserve that:
>>> b'\xaa %b' % b'123'
b'\xaa 123'Specifically, the u8 as char casting in this PR would map the non-ascii byte \xaa to the utf8 character sequence 'ª' == b'\xc2\xaa'. It's probably better than panicking, but it's lossy when it shouldn't need to be.
|
|
||
| #[derive(Debug, PartialEq)] | ||
| pub(crate) struct CFormatBytes { | ||
| parts: Vec<(usize, CFormatPart)>, |
There was a problem hiding this comment.
@coolreader18 do you have an example which distinguish bytes and str for the case?
4442e90 to
84fa251
Compare
No description provided.