-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vcf/io/writer/record: Add reference bases writer
- Loading branch information
Showing
2 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::io::{self, Write}; | ||
|
||
use crate::variant::record::ReferenceBases; | ||
|
||
pub(super) fn write_reference_bases<W, B>(writer: &mut W, reference_bases: B) -> io::Result<()> | ||
where | ||
W: Write, | ||
B: ReferenceBases, | ||
{ | ||
for result in reference_bases.iter() { | ||
let base = result?; | ||
writer.write_all(&[base])?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_write_reference_bases() -> io::Result<()> { | ||
let mut buf = Vec::new(); | ||
|
||
buf.clear(); | ||
write_reference_bases(&mut buf, "A")?; | ||
assert_eq!(buf, b"A"); | ||
|
||
buf.clear(); | ||
write_reference_bases(&mut buf, "AC")?; | ||
assert_eq!(buf, b"AC"); | ||
|
||
Ok(()) | ||
} | ||
} |