calls in statics are limited to constant functions, tuple structs and tuple variants
neilyoung opened this issue · 3 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
See https://docs.rs/state/0.4.1/state/#usage; you must enable the const_fn
feature.
P.S: Note that Rust nightly is no longer required.
SergioBenitez commented
0.4.2 was just released that makes this work on stable as well.
neilyoung commented
Yep. Already noticed. Thanks