Skip to main content

rlmesh_spaces/
advisory.rs

1//! Non-fatal adapter advisories with a severity tier.
2//!
3//! Advisories surface degradations the adapter tolerated instead of failing
4//! on: the consumer (an authoring warning, a serve-time log, an eval harness)
5//! decides what to do with them. The severity split exists so a harness can
6//! hard-fail on the dangerous tier without policing every note: `Caution`
7//! marks the adapter *substituting or fabricating* model-visible data (a
8//! role-rebound camera, a zero-filled frame), `Info` marks benign hints and
9//! lossy-but-requested steps (layout nudges, no-op ranges, crop/letterbox).
10
11use std::fmt;
12
13/// How much an advisory should worry an automated consumer.
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum AdvisorySeverity {
16    /// A benign note: an authoring nudge or an explicitly-requested lossy step.
17    Info,
18    /// The adapter substituted or fabricated data the model consumes; the run
19    /// proceeds, but the model may not be seeing what its author expects.
20    Caution,
21}
22
23impl AdvisorySeverity {
24    /// The stable lowercase wire/API name (`"info"` / `"caution"`).
25    pub fn as_str(self) -> &'static str {
26        match self {
27            Self::Info => "info",
28            Self::Caution => "caution",
29        }
30    }
31}
32
33/// One non-fatal note raised at join, resolve, or plan derivation.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct Advisory {
36    pub severity: AdvisorySeverity,
37    pub message: String,
38}
39
40impl Advisory {
41    /// A benign note (see [`AdvisorySeverity::Info`]).
42    pub fn info(message: impl Into<String>) -> Self {
43        Self {
44            severity: AdvisorySeverity::Info,
45            message: message.into(),
46        }
47    }
48
49    /// A data-substitution/fabrication note (see [`AdvisorySeverity::Caution`]).
50    pub fn caution(message: impl Into<String>) -> Self {
51        Self {
52            severity: AdvisorySeverity::Caution,
53            message: message.into(),
54        }
55    }
56}
57
58impl fmt::Display for Advisory {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        f.write_str(&self.message)
61    }
62}