Skip to content

Commit

Permalink
fastq/record: Interpret fields as UTF-8 encoded text when debug forma…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
zaeleus committed Jul 11, 2024
1 parent 6a71665 commit 7d6e81f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion noodles-fastq/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit 7d6e81f

Please sign in to comment.