mod builder;
pub(crate) mod tag;
pub use self::tag::Tag;
use std::{error, fmt};
use super::{Described, Inner, Map, OtherFields};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AlternativeAllele {
pub(crate) description: String,
}
impl Inner for AlternativeAllele {
type StandardTag = tag::Standard;
type Builder = builder::Builder;
}
impl Described for AlternativeAllele {
fn description(&self) -> &str {
&self.description
}
fn description_mut(&mut self) -> &mut String {
&mut self.description
}
}
impl Map<AlternativeAllele> {
pub fn new<D>(description: D) -> Self
where
D: Into<String>,
{
Self {
inner: AlternativeAllele {
description: description.into(),
},
other_fields: OtherFields::new(),
}
}
}
impl fmt::Display for Map<AlternativeAllele> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
super::fmt_display_description_field(f, self.description())?;
super::fmt_display_other_fields(f, self.other_fields())?;
Ok(())
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ParseError {
MissingField(Tag),
DuplicateTag(Tag),
InvalidId(crate::record::alternate_bases::allele::symbol::ParseError),
}
impl error::Error for ParseError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::InvalidId(e) => Some(e),
_ => None,
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MissingField(tag) => write!(f, "missing field: {tag}"),
Self::DuplicateTag(tag) => write!(f, "duplicate tag: {tag}"),
Self::InvalidId(_) => write!(f, "invalid ID"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_fmt() {
let map = Map::<AlternativeAllele>::new("Deletion");
let expected = r#",Description="Deletion""#;
assert_eq!(map.to_string(), expected);
}
}