feat: implement lightweight mode state management and initialization #3344, d05952e945

This commit is contained in:
Tunglies
2025-06-11 04:20:50 +08:00
parent f07d508018
commit 07738dd82d
6 changed files with 100 additions and 50 deletions

View File

@@ -0,0 +1,42 @@
use std::sync::Once;
use crate::{logging, utils::logging::Type};
pub struct LightWeightState {
#[allow(unused)]
once: Once,
pub is_lightweight: bool,
}
impl LightWeightState {
pub fn new() -> Self {
Self {
once: Once::new(),
is_lightweight: false,
}
}
#[allow(unused)]
pub fn run_once_time<F>(&self, f: F)
where
F: FnOnce() + Send + 'static,
{
self.once.call_once(f);
}
pub fn set_lightweight_mode(&mut self, value: bool) -> &Self {
self.is_lightweight = value;
if value {
logging!(info, Type::Lightweight, true, "轻量模式已开启");
} else {
logging!(info, Type::Lightweight, true, "轻量模式已关闭");
}
self
}
}
impl Default for LightWeightState {
fn default() -> Self {
Self::new()
}
}