SergioBenitez/state

Sample error

neilyoung opened this issue · 7 comments

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?

Closing as dup.

Thanks. This unfortunately gives

#![feature]` may not be used on the stable release channel

Anyway, don't bother. I will find alternatives
Thanks

Maybe a combination with lazy_static works, not sure...

lazy_static! {
pub static ref CONFIG: Storage<RwLock> = Storage::new();
}

Ah, this is a valid issue; the library should be upgraded. Will take care of it.

You mean you have a solution for the stable channel? This would be awesome....