I initialized the struct and passed the reference to the start_server function, and used below syntax to take the parameter, pub fn start_server(&config :&Config) -> io::Result<()>
But the compiler gave me the below error.
30 | pub fn start_server(&config :&Config) -> io::Result<()> {
| ^------
| ||
| |data moved here
| |move occurs because `config` has type `config::parser::Config<'_>`, which does not implement the `Copy` trait
| help: consider removing the `&`: `config`
I thought the above syntax is to allow config variable to be used without * symbol, I want to understand what is use case of this syntax.
Removing & as per the compiler resolves the error.
It does allow this, but it does so by copying the value, and you don't have a #[derive(Copy)] on your struct.
In your case, you should probably just take it by value instead. Note also that you should almost certainly be using String instead of &str in your config struct.
What if I don't want to copy the strings and just pass references because that struct is going to grow in the future, I thought passing references would be better and that is why added <'a>
Okay, I understood my multiple mistakes, strings will be copied at the time of struct initialization only , when I use without & for calling function it will be moved/owned not copied,
my last question is, does reference pattern always copy data?