Skip to main content

teaql_tool_core/
lib.rs

1pub mod audit;
2pub mod env_config;
3pub mod formatter;
4
5pub use audit::{AuditConfig, AuditLevel, Module};
6pub use env_config::{audit_config_from_env, AuditSink, EnvAuditConfig, SchemaMode};
7pub use formatter::{AuditFormatter, AuditDetail};
8
9use thiserror::Error;
10
11/// A unified error type for all TeaQL Tool operations.
12#[derive(Debug, Error)]
13pub enum TeaQLToolError {
14    #[error("Parse Error: {0}")]
15    ParseError(String),
16
17    #[error("Invalid Argument: {0}")]
18    InvalidArgument(String),
19
20    #[error("Execution Error: {0}")]
21    ExecutionError(String),
22
23    #[error("Not Supported: {0}")]
24    NotSupported(String),
25}
26
27/// A standard result type alias used throughout the TeaQL Tool ecosystem.
28pub type Result<T> = std::result::Result<T, TeaQLToolError>;
29
30/// A zero-cost wrapper that forces the developer (or AI) to provide a business comment.
31/// Without calling `.comment()`, the internal value cannot be extracted or used.
32/// This prevents un-annotated logic in the application layer.
33#[repr(transparent)]
34pub struct MustPurpose<T> {
35    value: T,
36}
37
38impl<T> MustPurpose<T> {
39    /// Internal constructor, used by the framework to wrap returned values.
40    #[inline(always)]
41    pub fn new(value: T) -> Self {
42        Self { value }
43    }
44
45    /// The ONLY way to extract the value. Enforces providing a business intent string.
46    /// In release builds, this is completely optimized away (Zero-Cost).
47    #[inline(always)]
48    pub fn purpose(self, _desc: impl Into<String>) -> T {
49        self.value
50    }
51}
52
53impl<T: std::fmt::Debug> std::fmt::Debug for MustPurpose<T> {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        std::fmt::Debug::fmt(&self.value, f)
56    }
57}