Iced and lifetimes
⚓ Rust 📅 2026-02-15 👤 surdeus 👁️ 2Trying to get the lifetimes correct for iced::run(...)
I have a Message enum:
#[derive(Debug, Clone)]
enum Message<'a> {
NewRolodex,
CategoriesPressed,
DelCategoryPressed(CategoryType, &'a str),
}
If I leave out the <'a> on the definition and the &str, the compiler tells me I need a named lifetime on them.
If I put in the named lifetime, the compiler tells me that the signature of iced::run isn't correct.
I presume that the problem is at least in part the signatures on my update and wview declarations, so I am including those here as well:
fn update<'a>(rolo: &'a mut RoloGuiState<'a>, message: Message<'a>) { ... }
fn view<'a>(rolo: &'a RoloGuiState<'a>) -> Element<'a, Message<'a>> { ... }
The RoloGuiState itself is:
struct RoloGuiState<'a> {
rolodex: Option<Rc<RolodexBase<'a>>>,
right_state: RoloRightGuiState<'a>,
}
and I have defined Default and Clone traits for that. The lifetime marks on that were added because in an earlier stage the compiler told me I needed them. I may have misunderstood the error.
Thank you,
Joel
5 posts - 2 participants
🏷️ Rust_feed