Skip to content

Implement Display for CStr and BStr #534

@ojeda

Description

@ojeda

In addition to #532, it would be nice to implement Display for CStr and BStr.

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 to Debug and just submit the bytes as-is for Display like printk() does for %s. But do we actually want this anyway? I don't know about a use case; in printk it is done like this because it is how printf works, I assume, and because we use macros to prefix the level etc.]

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomers• libRelated to the `rust/` library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions