Help in this very bad implementation of an iterator
⚓ Rust 📅 2025-11-22 👤 surdeus 👁️ 10 struct TheStruct<'a> {
buffer: Vec<Option<&'a u8>>,
}
trait FakeIterator<'a> {
fn into_iter(self) -> core::iter::FromFn<impl FnMut() -> Option<&'a mut Option<&'a u8>>>;
}
impl<'a> FakeIterator<'a> for &'a mut TheStruct<'a> {
fn into_iter(self) -> core::iter::FromFn<impl FnMut() -> Option<&'a mut Option<&'a u8>>> {
core::iter::from_fn(move || {
self.buffer.push(None);
let len = self.buffer.len() - 1;
(*self).buffer.get_mut(len)
})
}
}
I need help as such first I tried Iterator realizing 2 &mut alias
Then IntoIterator but realizing TAITs is needed but it's not stabilized
then this fakeIterator returning an iterator but the error keep saying "reference may escape in FnMut" (paraphased)
I wanted an iterator that never returns None (not iter::cycle as such clones to keep it alive) that mutates TheStruct
3 posts - 3 participants
🏷️ Rust_feed