extern crate ambassador; use ambassador::{delegatable_trait, Delegate}; #[delegatable_trait] pub trait StreamingIterator { type Output<'a> where Self: 'a; fn next(&mut self) -> Option>; } struct RepeatMut(T); impl StreamingIterator for RepeatMut { type Output<'a> = &'a mut T where T: 'a; fn next(&mut self) -> Option> { Some(&mut self.0) } } #[derive(Delegate)] #[delegate(StreamingIterator)] pub struct Wrap(X); pub fn main() { let mut x = Wrap(RepeatMut("forever".into())); let m: &mut String = x.next().unwrap(); m.push('?'); assert_eq!(x.next().unwrap(), "forever?"); }