1

I'm trying to generate HTML of elements inside of a vector, which will have a button to remove itself (the button). Here is my code:

pub struct App {
    pub elements: Vec<AppElement>
}

pub struct AppElement {}

impl Component for App {
    // ..
    fn view(&self, ctx: &Context<Self>) -> Html {
        let elements = self.elements.iter().map(|e| html! {
             <button onclick={ ctx.link().callback(|_| AppMsg::RemoveElement(e)) }>
             { "Remove" }
             </button>
        }).collect::<Html>();
        
        html! {
            { elements }
        }
    }
}

This code does not compile because the anonymous lifetime of iter() does not outlive the required static lifetime. Is there a way to achieve what I'm trying to do?

0 Answers0