Skip to main content

reifydb_sub_server_admin/
state.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Application state shared across admin request handler.
5
6use std::time::Duration;
7
8use reifydb_engine::engine::StandardEngine;
9
10/// Shared application state for admin handler.
11///
12/// This struct is cloneable and cheap to clone since `StandardEngine` uses
13/// `Arc` internally.
14#[derive(Clone)]
15pub struct AdminState {
16	engine: StandardEngine,
17	max_connections: usize,
18	request_timeout: Duration,
19	auth_required: bool,
20	auth_token: Option<String>,
21}
22
23impl AdminState {
24	/// Create a new AdminState.
25	pub fn new(
26		engine: StandardEngine,
27		max_connections: usize,
28		request_timeout: Duration,
29		auth_required: bool,
30		auth_token: Option<String>,
31	) -> Self {
32		Self {
33			engine,
34			max_connections,
35			request_timeout,
36			auth_required,
37			auth_token,
38		}
39	}
40
41	/// Get a reference to the database engine.
42	#[inline]
43	pub fn engine(&self) -> &StandardEngine {
44		&self.engine
45	}
46
47	/// Get a clone of the database engine.
48	#[inline]
49	pub fn engine_clone(&self) -> StandardEngine {
50		self.engine.clone()
51	}
52
53	/// Get the maximum connections.
54	#[inline]
55	pub fn max_connections(&self) -> usize {
56		self.max_connections
57	}
58
59	/// Get the request timeout.
60	#[inline]
61	pub fn request_timeout(&self) -> Duration {
62		self.request_timeout
63	}
64
65	/// Check if authentication is required.
66	#[inline]
67	pub fn auth_required(&self) -> bool {
68		self.auth_required
69	}
70
71	/// Get the auth token (if set).
72	#[inline]
73	pub fn auth_token(&self) -> Option<&str> {
74		self.auth_token.as_deref()
75	}
76}