Attempting to store a function with parameters in a Some variant

I had it working without passing parameters but now I get an expected function pointer, found function item error.

Code Snippet: Creating the menu and the function it's storing

fn create_menu() -> Menu {
    let mut menu = Menu::new("Main Menu".to_string(), "Make your selection: ".to_string());
    menu.add_item(MenuItem::new('A', "Add Movie".to_string(), Some(do_add))); //  Here's the error
    menu.add_item(MenuItem::new('E',  "Edit Movie".to_string(), None));
    menu.add_item(MenuItem::new('D', "Delete Movie".to_string(), None));
    menu.add_item(MenuItem::new('V', "View Movie".to_string(), None));
    menu.add_item(MenuItem::new('S', "Search Movies".to_string(), None));
    menu.add_item(MenuItem::new('Q', "Quit".to_string(), None));

    return menu;
}

fn do_add(movies: &Vec<MovieModel>) {
    println!("Doing nothing");
}

Code Snippet: the menu item:

use crate::{model::MovieModel, output};

#[derive(Clone)]
pub struct MenuItem {
    option: char,
    text: String,
    action: Option<fn(Vec<MovieModel>)>,
}

impl MenuItem {
    pub fn new(option: char, text: String, action: Option<fn(Vec<MovieModel>)>) -> MenuItem {
        return MenuItem {
            option, text, action
        };
    }

    pub fn get_option(&self) -> char {
        return self.option;
    }

    pub fn get_action(&self) -> Option<fn(Vec<MovieModel>)> {
        return self.action;
    }

    pub fn render(&self, new_line: bool) {
        let mut message = String::new();

        message.push(self.option);
        message.push_str(". ");
        message.push_str(&self.text);

        output::plain_text(&message, new_line);
    }
}

The full code can be found at GitHub - RichardGladman/movies-rust · GitHub

your function has an incompatible signature, you need a function pointer with an argument of type Vec<_>, but the function do_add has an argument of &Vec<...>.

if the function is supposed to take ownership of the data, then remove the reference & in do_add. if it should not take ownership, then a slice &[MovieModel] would be more idiomatic than a reference of a Vec.

Got it working! All I had to do was change Option<fn(Vec<MovieModel>)> to Option<fn(&Vec<MovieModel>)> in MenuItem.rs, now I try to understand the idiomatic way.

Thank you for the clue.

If I pass &[MovieModel] can I update, insert and delete from the vector using it?

No, you can't do that with &[_] -- and you can't do that with &Vec<_> either.

Use &mut Vec<_> if you need to change the size of the Vec, get &mut _ to the contents, etc.

Yeah, I plan to. I just haven't got there yet. Apart from hello world level examples, this is my first rust program so I'm taking it one step at a time.

Edit: Oh I see, I didn't include mut in my question.