Skip to content

Commit

Permalink
vcf/io/writer/record/info/field/value: Add character writer
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Sep 12, 2024
1 parent d5e814f commit 8343981
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions noodles-vcf/src/io/writer/record/info/field/value.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod array;
mod character;
mod string;

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

use self::{array::write_array, string::write_string};
use self::{array::write_array, character::write_character, string::write_string};
use crate::variant::record::info::field::Value;

pub(super) fn write_value<W>(writer: &mut W, value: &Value) -> io::Result<()>
Expand All @@ -14,7 +15,7 @@ where
Value::Integer(n) => write!(writer, "{n}"),
Value::Float(n) => write!(writer, "{n}"),
Value::Flag => Ok(()),
Value::Character(c) => write!(writer, "{c}"),
Value::Character(c) => write_character(writer, *c),
Value::String(s) => write_string(writer, s),
Value::Array(array) => write_array(writer, array),
}
Expand Down
28 changes: 28 additions & 0 deletions noodles-vcf/src/io/writer/record/info/field/value/character.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::io::{self, Write};

pub(super) fn write_character<W>(writer: &mut W, c: char) -> io::Result<()>
where
W: Write,
{
write!(writer, "{c}")
}

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

#[test]
fn test_write_character() -> io::Result<()> {
let mut buf = Vec::new();

buf.clear();
write_character(&mut buf, 'n')?;
assert_eq!(buf, b"n");

buf.clear();
write_character(&mut buf, ':')?;
assert_eq!(buf, b":"); // FIXME

Ok(())
}
}

0 comments on commit 8343981

Please sign in to comment.