Skip to content

Commit

Permalink
remove .value from positioned trait
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Sep 25, 2023
1 parent 90247ce commit 2a995f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
4 changes: 3 additions & 1 deletion src/bedder_bed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::useless_conversion)] // these are needed to support e.g. smartstring

use crate::position::{Field, FieldError, Position, Positioned, Value};
use crate::position::{Field, FieldError, Position, Positioned, Value, Valued};
use crate::string::String;
pub use bed::record::Record;
pub use noodles::bed;
Expand All @@ -23,7 +23,9 @@ impl crate::position::Positioned for bed::record::Record<3> {
fn stop(&self) -> u64 {
self.end_position().get() as u64
}
}

impl Valued for bed::record::Record<3> {
fn value(&self, v: crate::position::Field) -> result::Result<Value, FieldError> {
match v {
Field::String(s) => Ok(Value::Strings(vec![s])),
Expand Down
15 changes: 2 additions & 13 deletions src/bedder_vcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ where
}
}

/*
pub fn _from_reader<R: Read>(r: Box<R>) -> io::Result<BedderVCF<R>> {
let reader = xvcf::Reader::from_reader(r, None)?;
BedderVCF::new(reader)
}
*/

fn match_info_value(info: &vcf::record::Info, name: &str) -> result::Result<Value, FieldError> {
pub fn match_info_value(info: &vcf::record::Info, name: &str) -> result::Result<Value, FieldError> {
//let info = record.info();
let key: vcf::record::info::field::Key = name
.parse()
Expand Down Expand Up @@ -76,7 +69,7 @@ fn match_info_value(info: &vcf::record::Info, name: &str) -> result::Result<Valu
}
}

fn match_value(record: &vcf::record::Record, f: Field) -> result::Result<Value, FieldError> {
pub fn match_value(record: &vcf::record::Record, f: Field) -> result::Result<Value, FieldError> {
match f {
Field::String(s) => match s.as_str() {
"chrom" => Ok(Value::Strings(vec![String::from(Positioned::chrom(
Expand Down Expand Up @@ -131,10 +124,6 @@ impl Positioned for vcf::record::Record {
fn stop(&self) -> u64 {
usize::from(self.end().expect("error getting end from vcf record")) as u64
}

fn value(&self, f: crate::position::Field) -> result::Result<Value, FieldError> {
match_value(self, f)
}
}

impl<R> crate::position::PositionedIterator for BedderVCF<R>
Expand Down
25 changes: 10 additions & 15 deletions src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ pub trait Positioned: Debug {
/// non-inclusive end;
fn stop(&self) -> u64;

// extract a value from the Positioned object Col
fn value(&self, b: Field) -> result::Result<Value, FieldError>;

// get back the original line?
//fn line(&self) -> &'a str;
}

pub trait Valued {
// extract a value from the Positioned object Col
fn value(&self, b: Field) -> result::Result<Value, FieldError>;
}

#[derive(Debug)]
pub enum Position {
Bed(crate::bedder_bed::Record<3>),
Expand Down Expand Up @@ -98,16 +100,13 @@ impl Position {
Position::Other(o) => o.stop(),
}
}
}

#[cfg(feature = "dyn_positioned")]
impl Valued for Box<dyn Positioned> {
#[inline]
pub fn value(&self, f: Field) -> result::Result<Value, FieldError> {
match self {
Position::Bed(b) => b.value(f),
Position::Vcf(v) => v.value(f),
Position::Interval(i) => i.value(f),
#[cfg(feature = "dyn_positioned")]
Position::Other(o) => o.value(f),
}
fn value(&self, f: Field) -> result::Result<Value, FieldError> {
self.value(f)
}
}

Expand All @@ -124,10 +123,6 @@ impl Positioned for Box<dyn Positioned> {
fn stop(&self) -> u64 {
self.as_ref().stop()
}

fn value(&self, b: Field) -> result::Result<Value, FieldError> {
self.as_ref().value(b)
}
}

impl PartialEq for dyn Positioned {
Expand Down

0 comments on commit 2a995f2

Please sign in to comment.