use std::fmt;
use xmlparser::{
FromSpan,
Stream,
StrSpan,
};
use {
StreamExt,
};
#[derive(Clone, Copy, PartialEq)]
pub struct Points<'a>(Stream<'a>);
impl<'a> FromSpan<'a> for Points<'a> {
fn from_span(span: StrSpan<'a>) -> Self {
Points(Stream::from_span(span))
}
}
impl<'a> fmt::Debug for Points<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Points({:?})", self.0.span())
}
}
impl<'a> Iterator for Points<'a> {
type Item = (f64, f64);
fn next(&mut self) -> Option<Self::Item> {
if self.0.at_end() {
None
} else {
let x = match self.0.parse_list_number() {
Ok(x) => x,
Err(_) => return None,
};
let y = match self.0.parse_list_number() {
Ok(y) => y,
Err(_) => return None,
};
Some((x, y))
}
}
}