| 1 | # print\_bytes |
| 2 | |
| 3 | This crate allows printing broken UTF-8 bytes to an output stream as losslessly |
| 4 | as possible. |
| 5 | |
| 6 | Usually, paths are printed by calling [`Path::display`] or |
| 7 | [`Path::to_string_lossy`] beforehand. However, both of these methods are always |
| 8 | lossy; they misrepresent some valid paths in output. The same is true when |
| 9 | using [`String::from_utf8_lossy`] to print any other UTF-8–like byte sequence. |
| 10 | |
| 11 | Instead, this crate only performs a lossy conversion when the output device is |
| 12 | known to require Unicode, to make output as accurate as possible. When |
| 13 | necessary, any character sequence that cannot be represented will be replaced |
| 14 | with [`REPLACEMENT_CHARACTER`]. That convention is shared with the standard |
| 15 | library, which uses the same character for its lossy conversion functions. |
| 16 | |
| 17 | [](https://github.com/dylni/print_bytes/actions?query=branch%3Amaster) |
| 18 | |
| 19 | ## Usage |
| 20 | |
| 21 | Add the following lines to your "Cargo.toml" file: |
| 22 | |
| 23 | ```toml |
| 24 | [dependencies] |
| 25 | print_bytes = "1.2" |
| 26 | ``` |
| 27 | |
| 28 | See the [documentation] for available functionality and examples. |
| 29 | |
| 30 | ## Rust version support |
| 31 | |
| 32 | The minimum supported Rust toolchain version is currently Rust 1.63.0. |
| 33 | |
| 34 | Minor version updates may increase this version requirement. However, the |
| 35 | previous two Rust releases will always be supported. If the minimum Rust |
| 36 | version must not be increased, use a tilde requirement to prevent updating this |
| 37 | crate's minor version: |
| 38 | |
| 39 | ```toml |
| 40 | [dependencies] |
| 41 | print_bytes = "~1.2" |
| 42 | ``` |
| 43 | |
| 44 | ## License |
| 45 | |
| 46 | Licensing terms are specified in [COPYRIGHT]. |
| 47 | |
| 48 | Unless you explicitly state otherwise, any contribution submitted for inclusion |
| 49 | in this crate, as defined in [LICENSE-APACHE], shall be licensed according to |
| 50 | [COPYRIGHT], without any additional terms or conditions. |
| 51 | |
| 52 | [COPYRIGHT]: https://github.com/dylni/print_bytes/blob/master/COPYRIGHT |
| 53 | [documentation]: https://docs.rs/print_bytes |
| 54 | [LICENSE-APACHE]: https://github.com/dylni/print_bytes/blob/master/LICENSE-APACHE |
| 55 | [`Path::display`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.display |
| 56 | [`Path::to_string_lossy`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.to_string_lossy |
| 57 | [`REPLACEMENT_CHARACTER`]: https://doc.rust-lang.org/std/char/constant.REPLACEMENT_CHARACTER.html |
| 58 | [`String::from_utf8_lossy`]: https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf8_lossy |