Skip to content

Commit

Permalink
gff/io/writer/line/record: Add position writer
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Nov 25, 2024
1 parent ca0e91f commit 3c789e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions noodles-gff/src/io/writer/line/record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod position;

use std::io::{self, Write};

use self::position::write_position;
use crate::RecordBuf;

pub(crate) fn write_record<W>(writer: &mut W, record: &RecordBuf) -> io::Result<()>
Expand All @@ -15,10 +18,10 @@ where
writer.write_all(record.ty().as_bytes())?;
write_separator(writer)?;

write!(writer, "{}", record.start())?;
write_position(writer, record.start())?;
write_separator(writer)?;

write!(writer, "{}", record.end())?;
write_position(writer, record.end())?;
write_separator(writer)?;

if let Some(score) = record.score() {
Expand Down
23 changes: 23 additions & 0 deletions noodles-gff/src/io/writer/line/record/position.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::io::{self, Write};

use noodles_core::Position;

pub(super) fn write_position<W>(writer: &mut W, position: Position) -> io::Result<()>
where
W: Write,
{
write!(writer, "{}", position)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_write_position() -> io::Result<()> {
let mut buf = Vec::new();
write_position(&mut buf, Position::MIN)?;
assert_eq!(buf, b"1");
Ok(())
}
}

0 comments on commit 3c789e0

Please sign in to comment.