No, you cannot hide a private type in a public method. It is publicly available, which means that people should see it.
As delnan mentions , the wrapper structure is common to iterators. It also has zero execution cost:
struct Iter<'a>(FilterMap<slice::Iter<'a, AtomWord>, fn(&AtomWord) -> Option<Literal>>); impl<'a> Iterator for Iter<'a> { type Item = Literal; fn next(&mut self) -> Option<Literal> { self.0.next() } } impl<'a> IntoIterator for &'a NoGood { type Item = Literal; type IntoIter = Iter; fn into_iter(self) -> Self::IntoIter { Iter((&self.lits).into_iter().filter_map(as_opt_lit)) } }
And as ker mentions , you can install it. This saves programmer input time, but due to memory allocation at runtime:
impl<'a> IntoIterator for &'a NoGood { type Item = Literal; type IntoIter = Box<Iterator<Item = Literal>>; fn into_iter(self) -> Self::IntoIter { Box::new((&self.lits).into_iter().filter_map(as_opt_lit)) } }
Note that I did not try to compile any of them because you did not provide MCVE and thus your code does not compile in any way.
source share