#bytes #osstr #path #print #windows


Print bytes as losslessly as possible

15 releases (4 stable)

1.2.0 Apr 12, 2023
1.1.1 Feb 11, 2023
1.1.0 Jan 14, 2023
0.7.1 Jan 14, 2023
0.3.1 Jun 25, 2020

#104 in Operating systems

Download history 331/week @ 2023-08-10 449/week @ 2023-08-17 684/week @ 2023-08-24 304/week @ 2023-08-31 356/week @ 2023-09-07 291/week @ 2023-09-14 259/week @ 2023-09-21 272/week @ 2023-09-28 363/week @ 2023-10-05 520/week @ 2023-10-12 355/week @ 2023-10-19 357/week @ 2023-10-26 971/week @ 2023-11-02 340/week @ 2023-11-09 369/week @ 2023-11-16 372/week @ 2023-11-23

2,162 downloads per month
Used in 8 crates (5 directly)


441 lines


This crate allows printing broken UTF-8 bytes to an output stream as losslessly as possible.

Usually, paths are printed by calling Path::display or Path::to_string_lossy beforehand. However, both of these methods are always lossy; they misrepresent some valid paths in output. The same is true when using String::from_utf8_lossy to print any other UTF-8–like byte sequence.

Instead, this crate only performs a lossy conversion when the output device is known to require Unicode, to make output as accurate as possible. When necessary, any character sequence that cannot be represented will be replaced with REPLACEMENT_CHARACTER. That convention is shared with the standard library, which uses the same character for its lossy conversion functions.

GitHub Build Status


Add the following lines to your "Cargo.toml" file:

print_bytes = "1.2"

See the documentation for available functionality and examples.

Rust version support

The minimum supported Rust toolchain version is currently Rust 1.63.0.

Minor version updates may increase this version requirement. However, the previous two Rust releases will always be supported. If the minimum Rust version must not be increased, use a tilde requirement to prevent updating this crate's minor version:

print_bytes = "~1.2"


Licensing terms are specified in COPYRIGHT.

Unless you explicitly state otherwise, any contribution submitted for inclusion in this crate, as defined in LICENSE-APACHE, shall be licensed according to COPYRIGHT, without any additional terms or conditions.


~76K SLoC