#[derive(Clone, Debug)]
pub struct EffEncode<I: Iterator> {
iter: I,
}
impl<I, E> Iterator for EffEncode<I>
where
I: Iterator<Item = Result<u8, E>>,
{
type Item = Result<&'static str, E>;
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next()? {
Ok(byte) => Some(Ok(crate::WL_EFF_ENCODE[byte as usize])),
Err(e) => Some(Err(e)),
}
}
}
impl<I: Iterator<Item = Result<u8, E>>, E> crate::Encode<I, EffEncode<I>> for I {
fn encode(self) -> EffEncode<I> {
EffEncode { iter: self }
}
}
#[cfg(test)]
mod test_cases_encode {
use super::super::Encode;
use super::EffEncode;
use std::io::{Cursor, Read};
use test_case::test_case;
#[test_case(&[0x05u8; 3], &["acuteness"; 3] ; "data 0x05 0x05 0x05")]
fn test_positive_eff_encoder(bytes: &[u8], expected_words: &[&str]) {
let bytes = Cursor::new(bytes).bytes().into_iter();
let encoded_words = Encode::<_, EffEncode<_>>::encode(bytes)
.collect::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(encoded_words, expected_words);
}
}