use crate::{TryDecoder, Utf8Error};
pub struct Decoder<R>(TryDecoder<InfallibleInput<R>>);
impl<R> Decoder<R> {
pub fn new(source: R) -> Self {
Self(TryDecoder::new(InfallibleInput(source)))
}
}
impl<R> Iterator for Decoder<R>
where
R: Iterator<Item = u8>,
{
type Item = Result<char, Utf8Error>;
fn next(&mut self) -> Option<Result<char, Utf8Error>> {
self.0.next()
}
}
struct InfallibleInput<T>(T);
impl<T> Iterator for InfallibleInput<T>
where
T: Iterator<Item = u8>,
{
type Item = Result<u8, Utf8Error>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(Ok)
}
}