diff --git a/noodles-bed/Cargo.toml b/noodles-bed/Cargo.toml index c87d6f022..df2a3b2a3 100644 --- a/noodles-bed/Cargo.toml +++ b/noodles-bed/Cargo.toml @@ -12,4 +12,4 @@ documentation = "https://docs.rs/noodles-bed" [dependencies] noodles-core = { path = "../noodles-core", version = "0.7.0" } -serde = { version = "1" } \ No newline at end of file +serde = { version = "1", features = ["derive"] } \ No newline at end of file diff --git a/noodles-bed/src/de.rs b/noodles-bed/src/de.rs index dcb45226f..1d7b2fb90 100644 --- a/noodles-bed/src/de.rs +++ b/noodles-bed/src/de.rs @@ -13,40 +13,43 @@ use serde::de::{ use crate::{Record, reader::Reader, error::{Error, Result}}; const FIELDS: &'static [&'static str] = &["chrom", "start", "end"]; +// const FIELDS: &'static [&'static str] = &["Chrom", "Start", "End"]; + +#[derive(Deserialize, Debug)] enum Field { Chrom, Start, End } struct Record3Visitor; -impl<'de> Deserialize<'de> for Field { - fn deserialize(deserializer: D) -> std::result::Result - where - D: serde::Deserializer<'de>, - { - struct FieldVisitor; - - impl<'de> Visitor<'de> for FieldVisitor { - type Value = Field; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("`chrom`, `start` or `end`") - } - - fn visit_str(self, value: &str) -> std::result::Result - where - E: de::Error, - { - match value { - "chrom" => Ok(Field::Chrom), - "start" => Ok(Field::Start), - "end" => Ok(Field::End), - _ => Err(de::Error::unknown_field(value, FIELDS)), - } - } - } - - deserializer.deserialize_identifier(FieldVisitor) - } -} +// impl<'de> Deserialize<'de> for Field { +// fn deserialize(deserializer: D) -> std::result::Result +// where +// D: serde::Deserializer<'de>, +// { +// struct FieldVisitor; + +// impl<'de> Visitor<'de> for FieldVisitor { +// type Value = Field; + +// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { +// formatter.write_str("`chrom`, `start` or `end`") +// } + +// fn visit_str(self, value: &str) -> std::result::Result +// where +// E: de::Error, +// { +// match value { +// "chrom" => Ok(Field::Chrom), +// "start" => Ok(Field::Start), +// "end" => Ok(Field::End), +// _ => Err(de::Error::unknown_field(value, FIELDS)), +// } +// } +// } + +// deserializer.deserialize_identifier(FieldVisitor) +// } +// } impl<'de> Visitor<'de> for Record3Visitor { type Value = Record<3>; @@ -863,6 +866,8 @@ mod serde_tests { #[test] fn test_bed_single_deserialization() { + // wow this works + // let input = r#"{"Chrom":"sq0","Start":8,"End":13}"#; let input = r#"{"chrom":"sq0","start":8,"end":13}"#; let result: Record::<3> = from_str(input).unwrap();