8000 how to support uwrite! for CStr ? · Issue #33 · japaric/ufmt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
how to support uwrite! for CStr ? #33
Open
@mutantbob

Description

@mutantbob

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0