Skip to content

Commit

Permalink
vcf/variant/record_buf/samples/series: Implement crate::variant::reco…
Browse files Browse the repository at this point in the history
…rd::samples::Series
  • Loading branch information
zaeleus committed Feb 21, 2024
1 parent 419f93f commit e06fc33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion noodles-vcf/src/variant/record/samples/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ pub trait Series {
fn name(&self) -> &str;

/// Returns an iterator over values.
fn iter(&self) -> Box<dyn Iterator<Item = io::Result<Value<'_>>> + '_>;
fn iter(&self) -> Box<dyn Iterator<Item = io::Result<Option<Value<'_>>>> + '_>;
}
29 changes: 22 additions & 7 deletions noodles-vcf/src/variant/record_buf/samples/series.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::io;

use super::sample::Value;

/// A variant record samples buffer series.
Expand All @@ -12,11 +14,6 @@ impl<'a> Series<'a> {
Self { name, values, i }
}

/// Returns the name.
pub fn name(&self) -> &str {
self.name
}

/// Returns the value at the given index.
pub fn get(&self, i: usize) -> Option<Option<&Value>> {
self.values
Expand All @@ -25,11 +22,29 @@ impl<'a> Series<'a> {
}
}

impl<'a> crate::variant::record::samples::Series for Series<'a> {
fn name(&self) -> &str {
self.name
}

fn iter(
&self,
) -> Box<
dyn Iterator<Item = io::Result<Option<crate::variant::record::samples::series::Value<'_>>>>
+ '_,
> {
Box::new(self.values.iter().map(|sample| {
Ok(sample
.get(self.i)
.and_then(|value| value.as_ref().map(|v| v.into())))
}))
}
}

#[cfg(test)]
mod tests {
use crate::variant::record_buf::samples::keys::key;

use super::*;
use crate::variant::{record::samples::Series as _, record_buf::samples::keys::key};

#[test]
fn test_name() {
Expand Down

0 comments on commit e06fc33

Please sign in to comment.