Sha256: ab301ad59aa912529cb97233a54a05914dd3cb2ec43e6fec7334170b97ac5998

Contents?: true

Size: 981 Bytes

Versions: 30

Compression:

Stored size: 981 Bytes

Contents

/// A type that wraps a single byte with a convenient fmt::Debug impl that
/// escapes the byte.
pub(crate) struct DebugByte(pub(crate) u8);

impl core::fmt::Debug for DebugByte {
    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
        // Special case ASCII space. It's too hard to read otherwise, so
        // put quotes around it. I sometimes wonder whether just '\x20' would
        // be better...
        if self.0 == b' ' {
            return write!(f, "' '");
        }
        // 10 bytes is enough to cover any output from ascii::escape_default.
        let mut bytes = [0u8; 10];
        let mut len = 0;
        for (i, mut b) in core::ascii::escape_default(self.0).enumerate() {
            // capitalize \xab to \xAB
            if i >= 2 && b'a' <= b && b <= b'f' {
                b -= 32;
            }
            bytes[len] = b;
            len += 1;
        }
        write!(f, "{}", core::str::from_utf8(&bytes[..len]).unwrap())
    }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-28.0.0 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-27.0.0 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-26.0.0 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-25.0.2 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-25.0.1 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-25.0.0 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-24.0.0 ./ext/cargo-vendor/aho-corasick-1.1.3/src/util/debug.rs
wasmtime-23.0.2 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-22.0.0 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-21.0.1 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-20.0.2 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-20.0.0 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-18.0.3 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-17.0.1 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-17.0.0 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-16.0.0 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-15.0.1 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-15.0.0 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-14.0.4 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs
wasmtime-14.0.3 ./ext/cargo-vendor/aho-corasick-1.1.2/src/util/debug.rs