# 静态变量

## 可变静态变量

```
pub static mut EVENT_COUNTER: u32 = 0;
// 必须在 unsafe 中修改
unsafe {
   EVENT_COUNTER = 2；
}
// 必须在 unsafe 中使用
if unsafe { NET_PACKAGE_EVENT_SWITCH } == 2 {}
```

## 不可变静态常量

```
pub const NET_PACKAGE_EVENT: &'static str = "NET_PACKAGE_EVENT";
```

## lazy\_static 依赖

```
/// global event pool
lazy_static! {
    pub static ref EVENT_POOL: Mutex<HashMap<String, Event>> = {
        let mut map = HashMap::new();
        Mutex::new(map)
    };
}
```
