Sample error
neilyoung opened this issue · 7 comments
neilyoung commented
Hi, I'm trying to follow the example code here https://docs.rs/state/0.4.1/state/
The compiler complains
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
--> src/main.rs:7:49
|
7 | static CONFIG: Storage<RwLock<Configuration>> = Storage::new();
| ^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted
Code:
use state::Storage;
use std::sync::RwLock;
struct Configuration {}
static CONFIG: Storage<RwLock<Configuration>> = Storage::new();
fn main() {
let config = Configuration {
/* fill in structure at run-time from user input */
};
// Make the config avaiable globally.
CONFIG.set(RwLock::new(config));
/* at any point later in the program, in any thread */
let mut_config = CONFIG.get().write();
}
What am I missing?
SergioBenitez commented
Closing as dup.
neilyoung commented
Thanks. This unfortunately gives
#![feature]` may not be used on the stable release channel
neilyoung commented
Anyway, don't bother. I will find alternatives
Thanks
neilyoung commented
Maybe a combination with lazy_static works, not sure...
lazy_static! {
pub static ref CONFIG: Storage<RwLock> = Storage::new();
}
SergioBenitez commented
Ah, this is a valid issue; the library should be upgraded. Will take care of it.
neilyoung commented
You mean you have a solution for the stable channel? This would be awesome....
SergioBenitez commented
@neilyoung Yes.