-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Display
for CStr
and BStr
#534
Comments
Hi, I started implementing this and I have a couple of questions:
|
No
No, there are no way around that. I have considered defining I wonder if implementing |
As far as I understand the docs, nothing says a type should try to interpret contents as UTF-8 if possible. Our use case is printing some bytes into the kernel log. Whatever we do, we should avoid losing data. So escaping would be one way of doing that, but given |
There is no way to write bytes with formatter. |
Yeah, with the upstream formatter. But can it be extended to allow to emit to non-UTF-8 streams? After all, the formatting machinery seems like it could be reused without the target needing to be UTF-8 (I mean For instance, could we have a |
Not without a breaking change. You can call |
I am not sure I understand -- what I am proposing is to make If it is not doable (or reasonable, e.g. because we want always the same return type), then we would need something like |
Updated OP to leave this PR to the escaping case -- which seems reasonable and makes it a good "good first issue". |
If this problem has not been solved yet, I would like to contribute to solving this problem. |
Indeed, thanks Yutaro! |
In addition to #532, it would be nice to implement
Display
forCStr
andBStr
.Be careful to avoid panicking if invalid UTF-8 is found (i.e. do not attempt to convert it into a
&str
). We could escape all non-printable ASCII bytes to avoid losing data (e.g.\x01
). Another way (but lossy) is using a replacement character (e.g. the Unicode one).Unit-testing is a plus!
[If there was a
Display
-like trait that would work for non-UTF-8, we could leave the escaping toDebug
and just submit the bytes as-is forDisplay
likeprintk()
does for%s
. But do we actually want this anyway? I don't know about a use case; inprintk
it is done like this because it is howprintf
works, I assume, and because we use macros to prefix the level etc.]The text was updated successfully, but these errors were encountered: