I'm trying to use the &str
type in one of my struct.
this struct has an async new
method so I can read the parameter from the env file and create an instance. the problem is I can't fix the lifetime of it.
pub struct AppContext<'a>{
pub site_url: &'a str
}
impl<'a> AppContext<'a>{
pub async fn new()->AppContext<'a>{
//fill website url base on env variables
let site_url = std::env::var("WEBSITE_URL").unwrap_or("http://localhost:3000".to_string());
AppContext{
site_url: site_url.as_str()
}
}
}
it keep telling me cannot return value referencing local variable 'site_url' returns a value referencing data owned by the current function
how can I fix this?