Simply put, a &'static str has to be known at compile time.
I'm not sure why that library is requiring that, because it will prevent users from having any runtime-generated strings be used as the database name. As it's written, you would need to hardcode the database name in Rust, or use include_str! on a file that contained only the database name. The way it's written on the sofa side is very limiting, because it means you can't use a configuration file or environment variable to determine database name.
Thanks @cuviper and @FrecklySunbeam for your response. I was struggling with the the compiler for a few hours wondering why i was not able to fix it. Now i understand this better. will ask sofa crate devs to relax the lifetime here.
Take a look at the source; if it really doesn't seem that it's necessary then you can probably use some unsafe magic to get around it until they change the requirements.
Compiler suggest this.. am i doing anything wrong?
can't capture dynamic environment in a fn item
help: use the || { ... } closure form instead rustc(E0434)
let cfg = serde_json::from_str::(&json).unwrap();
Don't use const (you're not creating a const), just a normal let binding.
Instead of leaking the string, as a workaround until sofa is changed, I'd probably just transmute the lifetime to be &'static just for the call to client.db(...).