So here is a snippet of code
pub struct SavedItemCard {
saved_item: SavedItem,
button_state: button::State,
}
impl SavedItemCard {
pub fn new(saved_item: SavedItem) -> Self {
Self {
saved_item,
button_state: button::State::new(),
}
}
fn view_submission_card(&mut self, submission: &SavedSubmission) -> Element<CardMessage> {
Container::new(
Column::new()
).into()
}
fn view_comment_card(&mut self, _comment: &SavedComment) -> Element<CardMessage> {
Container::new(
Column::new()
).into()
}
fn view(&mut self) -> Element<CardMessage> {
match self.saved_item {
SavedItem::Comment(comment) => self.view_comment_card(&comment),
SavedItem::Submission(submission) => self.view_submission_card(&submission),
}
}
}
The idea behind what I am trying to do is I match on the enum member and depending on the value call the appropriate function. The reason I am passing the inner struct of the enum as an argument is so that I don't match again within the function.
But the compiler tells me:
error[E0507]: cannot move out of self.saved_item.0 which is behind a mutable reference
It then suggests to borrow the self.saved_item
, but that leads to other issues such as cannot borrow *self as mutable more than once.
I don't really see what I am doing wrong here. Is there a better, correct way of doing this?