Skip to content

Commit

Permalink
fasta/record/sequence/complement: Print invalid base as a byte string
Browse files Browse the repository at this point in the history
The previous message incorrectly printed the invalid base without a hex
prefix. Instead of printing all characters in hex, this now prints the debug
output of a byte string, i.e., printable characters are shown normally
and non-printable characters are escaped.

See COMBINE-lab/simpleaf#137.
  • Loading branch information
zaeleus committed Jun 4, 2024
1 parent 6e34653 commit 30ba40a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions noodles-fasta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ documentation = "https://docs.rs/noodles-fasta"
async = ["dep:tokio"]

[dependencies]
bstr.workspace = true
bytes.workspace = true
memchr.workspace = true
noodles-bgzf = { path = "../noodles-bgzf", version = "0.30.0" }
Expand Down
5 changes: 4 additions & 1 deletion noodles-fasta/src/record/sequence/complement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use std::{error, fmt, iter::FusedIterator, slice};

use bstr::ByteSlice;

/// An iterator that returns the complement of a sequence.
pub struct Complement<'a> {
iter: slice::Iter<'a, u8>,
Expand All @@ -21,7 +23,8 @@ impl error::Error for ComplementError {}

impl fmt::Display for ComplementError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "invalid base: {:04x?}", self.0)
let bytes = [self.0];
write!(f, "invalid base: {:?}", bytes.as_bstr())
}
}

Expand Down

0 comments on commit 30ba40a

Please sign in to comment.