17 releases (6 stable)

2.0.1 Aug 11, 2024
2.0.0 Feb 10, 2024
1.3.0 Feb 10, 2024
1.2.0 Apr 12, 2023
0.3.1 Jun 25, 2020

#119 in Operating systems

Download history 290/week @ 2024-08-22 240/week @ 2024-08-29 233/week @ 2024-09-05 278/week @ 2024-09-12 313/week @ 2024-09-19 206/week @ 2024-09-26 226/week @ 2024-10-03 209/week @ 2024-10-10 357/week @ 2024-10-17 206/week @ 2024-10-24 219/week @ 2024-10-31 217/week @ 2024-11-07 263/week @ 2024-11-14 362/week @ 2024-11-21 485/week @ 2024-11-28 299/week @ 2024-12-05

1,434 downloads per month
Used in 7 crates (4 directly)

MIT/Apache

26KB
420 lines

print_bytes

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

Usage

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

[dependencies]
print_bytes = "2.0"

See the documentation for available functionality and examples.

Rust version support

The minimum supported Rust toolchain version is currently Rust 1.74.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:

[dependencies]
print_bytes = "~2.0"

License

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.

Dependencies

~0–7.5MB
~55K SLoC