From 7d6e81f5ce63f9b30894ab77282a514f0e05570b Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Thu, 11 Jul 2024 14:32:34 -0500 Subject: [PATCH] fastq/record: Interpret fields as UTF-8 encoded text when debug formatting --- noodles-fastq/src/record.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/noodles-fastq/src/record.rs b/noodles-fastq/src/record.rs index 67c1f9251..da8799497 100644 --- a/noodles-fastq/src/record.rs +++ b/noodles-fastq/src/record.rs @@ -4,8 +4,10 @@ mod definition; pub use self::definition::Definition; +use std::fmt; + /// A FASTQ record. -#[derive(Clone, Default, Debug, Eq, PartialEq)] +#[derive(Clone, Default, Eq, PartialEq)] pub struct Record { definition: Definition, sequence: Vec, @@ -165,6 +167,24 @@ impl Record { } } +impl fmt::Debug for Record { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use std::str; + + let name = str::from_utf8(self.name()); + let description = str::from_utf8(self.description()); + let sequence = str::from_utf8(self.sequence()); + let quality_scores = str::from_utf8(self.quality_scores()); + + f.debug_struct("Record") + .field("name", &name) + .field("description", &description) + .field("sequence", &sequence) + .field("quality_scores", &quality_scores) + .finish() + } +} + #[cfg(test)] mod tests { use super::*;