use crate::{
EMLError, NS_KR,
io::{EMLElement, EMLElementReader, EMLElementWriter, QualifiedName, collect_struct},
};
#[derive(Debug, Clone)]
pub struct ElectionTree {
pub regions: Vec<ElectionTreeRegion>,
}
impl ElectionTree {
pub fn new(regions: impl Into<Vec<ElectionTreeRegion>>) -> Self {
ElectionTree {
regions: regions.into(),
}
}
}
impl From<Vec<ElectionTreeRegion>> for ElectionTree {
fn from(regions: Vec<ElectionTreeRegion>) -> Self {
ElectionTree::new(regions)
}
}
impl EMLElement for ElectionTree {
const EML_NAME: QualifiedName<'_, '_> = QualifiedName::from_static("ElectionTree", Some(NS_KR));
fn read_eml(elem: &mut EMLElementReader<'_, '_>) -> Result<Self, EMLError> {
Ok(collect_struct!(elem, ElectionTree {
regions as Vec: ElectionTreeRegion::EML_NAME => |elem| ElectionTreeRegion::read_eml(elem)?,
}))
}
fn write_eml(&self, writer: EMLElementWriter) -> Result<(), EMLError> {
writer
.child_elems(ElectionTreeRegion::EML_NAME, &self.regions)?
.finish()
}
}
#[derive(Debug, Clone)]
pub struct ElectionTreeRegion {}
impl EMLElement for ElectionTreeRegion {
const EML_NAME: QualifiedName<'_, '_> = QualifiedName::from_static("Region", Some(NS_KR));
fn read_eml(elem: &mut EMLElementReader<'_, '_>) -> Result<Self, EMLError> {
elem.skip()?;
Ok(ElectionTreeRegion {})
}
fn write_eml(&self, writer: EMLElementWriter) -> Result<(), EMLError> {
writer.empty()
}
}