Skip to main content

cbtop/brick/
mod.rs

1//! Core Brick trait and types (PROBAR-SPEC-009 alignment)
2//!
3//! # Brick Invariants (MANDATORY)
4//!
5//! 1. `assertions().len() > 0` - At least one falsifiable claim
6//! 2. `verify()` checks ALL assertions - No skipping
7//! 3. `can_render() == verify().is_valid()` - Jidoka gate
8//! 4. `budget().total_ms() > 0` - Performance accountability
9//!
10//! # Reference
11//!
12//! Popper, K. (1959). "The Logic of Scientific Discovery"
13//! - A theory that makes no falsifiable predictions is not scientific.
14
15mod profiler;
16mod score;
17#[cfg(test)]
18mod tests;
19mod types;
20mod widget;
21
22use std::any::Any;
23
24// Re-export all public items so `use crate::brick::*` still works
25pub use profiler::BrickProfiler;
26pub use score::{BrickGrade, BrickScore, Scorable};
27pub use types::{
28    fnv1a_f32, BrickAssertion, BrickBudget, BrickVerification, DivergenceReport, KernelTrace,
29};
30pub use widget::{Canvas, Color, Constraints, Point, Rect, Size, TextStyle, Widget};
31
32/// Core Brick trait - all cbtop components implement this.
33///
34/// Provides quality infrastructure: assertions, budgets, verification.
35pub trait Brick: Send + Sync {
36    /// Unique brick name for identification
37    fn brick_name(&self) -> &'static str;
38
39    /// Falsifiable assertions (MUST be non-empty per Popper)
40    fn assertions(&self) -> Vec<BrickAssertion>;
41
42    /// Performance budget (Muda elimination)
43    fn budget(&self) -> BrickBudget;
44
45    /// Verification (Jidoka gate)
46    fn verify(&self) -> BrickVerification;
47
48    /// Test identifier for automation
49    fn test_id(&self) -> Option<&str> {
50        None
51    }
52
53    /// Can this brick render? (Jidoka gate)
54    fn can_render(&self) -> bool {
55        self.verify().is_valid()
56    }
57
58    /// Downcast to concrete type for assertion validation
59    fn as_any(&self) -> &dyn Any;
60}