From dc131cc9f134e64a55fbea00ca923dc35e1fe4b2 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:07:17 +0000 Subject: [PATCH] Replace MappedWrite's magic u8 constant with byte string literal The `NEWLINE_ASCII_BYTE` constant only really existed because it's otherwise not obvious that the `0x0Au8` u8 value represents an ASCII newline byte. However, we can replace the `0x0Au8` u8 with a byte string literal of `b'\n'` which is identical in it's value, but much easier to reason about. The byte string literal form is what the Rust stdlib uses in several places: https://github.com/rust-lang/rust/blob/1.76.0/library/core/src/num/mod.rs#L1023 https://github.com/rust-lang/rust/blob/1.76.0/library/core/src/escape.rs#L20 https://github.com/rust-lang/rust/blob/1.76.0/library/std/src/io/buffered/linewritershim.rs#L47 --- libherokubuildpack/src/write.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libherokubuildpack/src/write.rs b/libherokubuildpack/src/write.rs index a7bd0221..1a2bbff1 100644 --- a/libherokubuildpack/src/write.rs +++ b/libherokubuildpack/src/write.rs @@ -16,7 +16,7 @@ pub fn mapped) -> Vec) + Sync + Send + 'static> MappedWrite::new(w, marker_byte, f) } -/// Constructs a writer that buffers written data until an ASCII/UTF-8 newline byte (`0x0A`) is +/// Constructs a writer that buffers written data until an ASCII/UTF-8 newline byte (`b'\n'`) is /// encountered and then applies the given mapping function to the data before passing the result to /// the wrapped writer. /// @@ -25,7 +25,7 @@ pub fn line_mapped) -> Vec) + Sync + Send + 'st w: W, f: F, ) -> MappedWrite { - mapped(w, NEWLINE_ASCII_BYTE, f) + mapped(w, b'\n', f) } /// Constructs a writer that writes to two other writers. Similar to the UNIX `tee` command. @@ -155,8 +155,6 @@ impl io::Write for TeeWrite { } } -const NEWLINE_ASCII_BYTE: u8 = 0x0Au8; - #[cfg(test)] mod test { use super::tee;