Open
Description
Working in the Rust/Arduino environment I find myself occasionally dealing with C-style (NUL-terminated) strings when I'm interacting with preexisting C libraries.
While I would like to be able to write
use cstr_core::cstr;
let server_name = cstr!("www.purplefrog.com");
let _ = uwriteln!(&mut serial, "connecting to {}...", server_name);
I get
error[E0277]: the trait bound `CStr: uDisplay` is not satisfied
--> src/web_client.rs:89:13
|
89 | let _ = uwriteln!(&mut serial, "connecting to {}...", server_name);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `uDisplay` is not implemented for `CStr`
|
::: /home/thoth/.cargo/registry/src/github.com-1ecc6299db9ec823/ufmt-0.1.0/src/lib.rs:268:12
|
268 | W: uWrite + ?Sized;
| ------ required by this bound in `ufmt::uDisplay::fmt`
|
= note: required because of the requirements on the impl of `uDisplay` for `&CStr`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
So instead I have to
let _ = uwrite!(&mut serial, "connecting to ");
for ch in server_name.to_bytes() {
let _ = serial.write_byte(*ch);
}
let _ = uwriteln!(&mut serial, "...");
I am not sure if the cstr_core
crate should impl uDisplay for &CStr
or if ufmt
should do it, or maybe use server_name.to_bytes()
to get a &[u8]
and have ufmt impl uDisplay for &[u8]
Metadata
Metadata
Assignees
Labels
No labels