#![feature(impl_trait_in_assoc_type)] // check-pass trait IterBits { type BitsIter: Iterator; fn iter_bits(self, n: u8) -> Self::BitsIter; } impl IterBits for T where T: std::ops::Shr + std::ops::BitAnd + std::convert::From + std::convert::TryInto, E: std::fmt::Debug, { type BitsIter = impl std::iter::Iterator; fn iter_bits(self, n: u8) -> Self::BitsIter { (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap()) } } fn main() {}