How do i fix this issue?
fn main() {
let config = get_config();
let automation = Automation::new(&config);
println!("{}", automation.config.name);
}
struct Config {
pub name: String
}
fn get_config() -> Config {
Config {
name: "test".to_string()
}
}
struct Automation {
pub config: &'static Config
}
impl Automation {
pub fn new(config: &'static Config) -> Self {
Automation {
config
}
}
}
When i compile this i get this error
error[E0597]: `config` does not live long enough
--> src/main.rs:4:38
|
4 | let automation = Automation::new(&config);
| ----------------^^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `config` is borrowed for `'static`
...
8 | }
| - `config` dropped here while still borrowed
I am newb to rust...am i doing something wrong?