Use recently stabilized std::sync::LazyLock and remove lazy_static
This commit is contained in:
parent
eead7e1573
commit
f0fe7622b2
6 changed files with 23 additions and 26 deletions
|
@ -17,7 +17,6 @@ encoding = "0.2.33"
|
|||
env_logger = "0.11.3"
|
||||
heck = "0.5.0"
|
||||
hex = "0.4.3"
|
||||
lazy_static = "1.4.0"
|
||||
leb128 = "0.2.5"
|
||||
paste = "1.0.14"
|
||||
sysinfo = "0.30.7"
|
||||
|
|
|
@ -9,7 +9,6 @@ anyhow.workspace = true
|
|||
dirs.workspace = true
|
||||
env_logger.workspace = true
|
||||
hex.workspace = true
|
||||
lazy_static.workspace = true
|
||||
paste.workspace = true
|
||||
sysinfo.workspace = true
|
||||
itertools.workspace = true
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::sync::LazyLock;
|
||||
|
||||
use common::util::load_or_create_config;
|
||||
use lazy_static::lazy_static;
|
||||
use serde::Deserialize;
|
||||
|
||||
const DEFAULT_CONFIG: &str = include_str!("../gameserver.default.json");
|
||||
|
@ -11,12 +12,11 @@ pub struct GameServerConfig {
|
|||
pub system_resources_logging: bool,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIGURATION: GameServerConfig =
|
||||
serde_json::from_str(&load_or_create_config("gameserver.json", DEFAULT_CONFIG))
|
||||
.expect("Failed to parse server configuration file");
|
||||
}
|
||||
pub static CONFIGURATION: LazyLock<GameServerConfig> = LazyLock::new(|| {
|
||||
serde_json::from_str(&load_or_create_config("gameserver.json", DEFAULT_CONFIG))
|
||||
.expect("Failed to parse server configuration file")
|
||||
});
|
||||
|
||||
pub fn init_config() {
|
||||
let _configuration = &*CONFIGURATION; // init static
|
||||
let _configuration = &*CONFIGURATION;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
use lazy_static::lazy_static;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
pub const EVENT_GRAPH_COLLECTION: &str = include_str!("../../EventGraphCollection.json");
|
||||
|
||||
lazy_static! {
|
||||
static ref EVENT_MAP: Map<String, Value> = {
|
||||
serde_json::from_str::<Value>(EVENT_GRAPH_COLLECTION)
|
||||
.unwrap()
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.clone()
|
||||
};
|
||||
}
|
||||
static EVENT_MAP: LazyLock<Map<String, Value>> = LazyLock::new(|| {
|
||||
serde_json::from_str::<Value>(EVENT_GRAPH_COLLECTION)
|
||||
.unwrap()
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.clone()
|
||||
});
|
||||
|
||||
pub fn get_event_config_json(id: i32) -> &'static Value {
|
||||
EVENT_MAP.get(&id.to_string()).unwrap()
|
||||
|
|
|
@ -17,7 +17,6 @@ serde.workspace = true
|
|||
serde_json.workspace = true
|
||||
tokio-util.workspace = true
|
||||
ansi_term.workspace = true
|
||||
lazy_static.workspace = true
|
||||
rand.workspace = true
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::sync::LazyLock;
|
||||
|
||||
use axum::{body::Body, response::IntoResponse};
|
||||
use lazy_static::lazy_static;
|
||||
use rand::Rng;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
|
@ -11,11 +12,11 @@ pub const SERVER_LIST_ENDPOINT: &str =
|
|||
"/design_data/NAP_Publish_AppStore_0.1.0/oversea/serverlist.bin";
|
||||
pub const VERSIONS_BUNDLE_ENDPOINT: &str = "/game_res/NAP_Publish/output_147608_1361f678bc/client/StandaloneWindows64/oversea/versions.bundle";
|
||||
|
||||
lazy_static! {
|
||||
static ref APP_CONFIG: AppConfig = read_config("config.json");
|
||||
static ref SERVER_LIST: Vec<ServerListInfo> = read_config("serverlist.json");
|
||||
static ref VERSIONS_BUNDLE: Box<[u8]> = read_binary_data("versions.bundle");
|
||||
}
|
||||
static APP_CONFIG: LazyLock<AppConfig> = LazyLock::new(|| read_config("config.json"));
|
||||
static SERVER_LIST: LazyLock<Vec<ServerListInfo>> =
|
||||
LazyLock::new(|| read_config("serverlist.json"));
|
||||
|
||||
static VERSIONS_BUNDLE: LazyLock<Box<[u8]>> = LazyLock::new(|| read_binary_data("versions.bundle"));
|
||||
|
||||
pub async fn application() -> Vec<u8> {
|
||||
crypto::encrypt_config(
|
||||
|
|
Loading…
Reference in a new issue