webmetro/src/slice.rs

19 lines
510 B
Rust
Raw Normal View History

2018-04-04 04:43:25 +00:00
use futures::Async;
2018-04-04 05:21:13 +00:00
2018-12-22 20:03:19 +00:00
use crate::ebml::EbmlError;
use crate::ebml::EbmlEventSource;
use crate::ebml::FromEbml;
2018-04-04 04:43:25 +00:00
pub struct EbmlSlice<'a>(pub &'a [u8]);
impl<'b> EbmlEventSource for EbmlSlice<'b> {
type Error = EbmlError;
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, EbmlError> {
T::decode_element(self.0).map(|option| option.map(|(element, element_size)| {
self.0 = &self.0[element_size..];
element
})).map(Async::Ready)
2018-04-04 04:43:25 +00:00
}
}