I have a struct
struct MyStruct {
item: u32,
}
and a trait
trait MyTrait {
fn my_fn(&self) {
println!("Hello");
}
}
and I'd like to implement MyTrait for iterators over owned and referenced MyStructs. I've tried something along the lines of:
impl<I: AsRef<MyStruct>, T: IntoIterator<Item = I>> MyTrait for T{}
but this results in no method named my_fn found for struct std::slice::Iter in the current scope. I've also tried with Item=MyStruct rather than the generic using AsRef, but then I can only implement the trait for iterators of either owned or borrowed MyStructs, but not both
Here's a playground link https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=72812bc9723a66820b55f387e8658283
A browser interface to the Rust compiler to experiment with the language