pub struct AppState { /* private fields */ }Expand description
线程安全的应用状态,包含服务标识、生命周期及流控所需的并发计数器。
历史上的 peak_processing / total_requests / error_requests 等
统计字段已迁移到 Prometheus(见 src/metrics.rs 与 tibba-middleware),
这里只保留流控判断必须的 processing 原子计数。
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(processing_limit: i32, commit_id: impl Into<String>) -> Self
pub fn new(processing_limit: i32, commit_id: impl Into<String>) -> Self
创建 AppState,传入最大并发限制和 Git 提交 ID,其余字段使用默认值。
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
设置语义化版本号,支持链式调用。
Sourcepub fn get_version(&self) -> &str
pub fn get_version(&self) -> &str
返回语义化版本号。
Sourcepub fn get_commit_id(&self) -> &str
pub fn get_commit_id(&self) -> &str
返回 Git 提交 ID。
Sourcepub fn get_processing_limit(&self) -> i32
pub fn get_processing_limit(&self) -> i32
返回配置的最大并发请求数。
Sourcepub fn inc_processing(&self) -> i32
pub fn inc_processing(&self) -> i32
原子性地递增处理计数器,返回递增后的当前并发数。
仅用于 processing_limit 流控判断;统计指标由 Prometheus 负责。
Sourcepub fn dec_processing(&self) -> i32
pub fn dec_processing(&self) -> i32
原子性地递减处理计数器,返回递减后的当前并发数。
Sourcepub fn get_processing(&self) -> i32
pub fn get_processing(&self) -> i32
返回当前正在处理的请求数。
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
返回 true 表示应用当前处于运行状态。
Sourcepub fn get_started_at(&self) -> SystemTime
pub fn get_started_at(&self) -> SystemTime
返回应用的启动时间。
Auto Trait Implementations§
impl !Freeze for AppState
impl RefUnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
impl UnwindSafe for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more