Use recently stabilized std::sync::LazyLock and remove lazy_static

This commit is contained in:
xeon 2024-05-27 23:19:03 +03:00
parent eead7e1573
commit f0fe7622b2
6 changed files with 23 additions and 26 deletions

View file

@ -17,7 +17,6 @@ encoding = "0.2.33"
env_logger = "0.11.3" env_logger = "0.11.3"
heck = "0.5.0" heck = "0.5.0"
hex = "0.4.3" hex = "0.4.3"
lazy_static = "1.4.0"
leb128 = "0.2.5" leb128 = "0.2.5"
paste = "1.0.14" paste = "1.0.14"
sysinfo = "0.30.7" sysinfo = "0.30.7"

View file

@ -9,7 +9,6 @@ anyhow.workspace = true
dirs.workspace = true dirs.workspace = true
env_logger.workspace = true env_logger.workspace = true
hex.workspace = true hex.workspace = true
lazy_static.workspace = true
paste.workspace = true paste.workspace = true
sysinfo.workspace = true sysinfo.workspace = true
itertools.workspace = true itertools.workspace = true

View file

@ -1,5 +1,6 @@
use std::sync::LazyLock;
use common::util::load_or_create_config; use common::util::load_or_create_config;
use lazy_static::lazy_static;
use serde::Deserialize; use serde::Deserialize;
const DEFAULT_CONFIG: &str = include_str!("../gameserver.default.json"); const DEFAULT_CONFIG: &str = include_str!("../gameserver.default.json");
@ -11,12 +12,11 @@ pub struct GameServerConfig {
pub system_resources_logging: bool, pub system_resources_logging: bool,
} }
lazy_static! { pub static CONFIGURATION: LazyLock<GameServerConfig> = LazyLock::new(|| {
pub static ref CONFIGURATION: GameServerConfig = serde_json::from_str(&load_or_create_config("gameserver.json", DEFAULT_CONFIG))
serde_json::from_str(&load_or_create_config("gameserver.json", DEFAULT_CONFIG)) .expect("Failed to parse server configuration file")
.expect("Failed to parse server configuration file"); });
}
pub fn init_config() { pub fn init_config() {
let _configuration = &*CONFIGURATION; // init static let _configuration = &*CONFIGURATION;
} }

View file

@ -1,17 +1,16 @@
use lazy_static::lazy_static; use std::sync::LazyLock;
use serde_json::{Map, Value}; use serde_json::{Map, Value};
pub const EVENT_GRAPH_COLLECTION: &str = include_str!("../../EventGraphCollection.json"); pub const EVENT_GRAPH_COLLECTION: &str = include_str!("../../EventGraphCollection.json");
lazy_static! { static EVENT_MAP: LazyLock<Map<String, Value>> = LazyLock::new(|| {
static ref EVENT_MAP: Map<String, Value> = { serde_json::from_str::<Value>(EVENT_GRAPH_COLLECTION)
serde_json::from_str::<Value>(EVENT_GRAPH_COLLECTION) .unwrap()
.unwrap() .as_object()
.as_object() .unwrap()
.unwrap() .clone()
.clone() });
};
}
pub fn get_event_config_json(id: i32) -> &'static Value { pub fn get_event_config_json(id: i32) -> &'static Value {
EVENT_MAP.get(&id.to_string()).unwrap() EVENT_MAP.get(&id.to_string()).unwrap()

View file

@ -17,7 +17,6 @@ serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
tokio-util.workspace = true tokio-util.workspace = true
ansi_term.workspace = true ansi_term.workspace = true
lazy_static.workspace = true
rand.workspace = true rand.workspace = true
[[bin]] [[bin]]

View file

@ -1,5 +1,6 @@
use std::sync::LazyLock;
use axum::{body::Body, response::IntoResponse}; use axum::{body::Body, response::IntoResponse};
use lazy_static::lazy_static;
use rand::Rng; use rand::Rng;
use serde::de::DeserializeOwned; 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"; "/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"; pub const VERSIONS_BUNDLE_ENDPOINT: &str = "/game_res/NAP_Publish/output_147608_1361f678bc/client/StandaloneWindows64/oversea/versions.bundle";
lazy_static! { static APP_CONFIG: LazyLock<AppConfig> = LazyLock::new(|| read_config("config.json"));
static ref APP_CONFIG: AppConfig = read_config("config.json"); static SERVER_LIST: LazyLock<Vec<ServerListInfo>> =
static ref SERVER_LIST: Vec<ServerListInfo> = read_config("serverlist.json"); LazyLock::new(|| read_config("serverlist.json"));
static ref VERSIONS_BUNDLE: Box<[u8]> = read_binary_data("versions.bundle");
} static VERSIONS_BUNDLE: LazyLock<Box<[u8]>> = LazyLock::new(|| read_binary_data("versions.bundle"));
pub async fn application() -> Vec<u8> { pub async fn application() -> Vec<u8> {
crypto::encrypt_config( crypto::encrypt_config(