[][src]Crate 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.

Features

These features are optional and can be enabled or disabled in a "Cargo.toml" file. Nightly features are unstable, since they rely on unstable Rust features.

Default Features

  • os_str - Provides implementations of ToBytes for OsStr and other similar structs, such as Path. As a result, they can be output using functions in this crate.

Nightly Features

  • const_generics - Provides an implementation of ToBytes for [u8; N]. As a result, it can be output using functions in this crate.

  • specialization - Provides write_bytes.

Examples

use std::env;

use print_bytes::println_bytes;

print!("exe: ");
println_bytes(&env::current_exe()?);
println!();

println!("args:");
for arg in env::args_os().skip(1) {
    println_bytes(&arg);
}

Structs

Bytes

A value that can be printed by any of the functions in this crate.

Traits

ToBytes

Represents a type similarly to Display.

Functions

eprint_bytes

Prints a value to the standard error stream.

eprintln_bytes

Prints a value to the standard error stream, followed by a newline.

print_bytes

Prints a value to the standard output stream.

println_bytes

Prints a value to the standard output stream, followed by a newline.

write_bytes

Writes a value to a "writer".