Skip to main content

kernel/error/
refusal.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! Gate refusals: the three mandatory parts.
7//! The part `crates/kernel/spec/Error.lean` specifies this module with the
8//! rest of `kernel::error`.
9
10use serde::{Deserialize, Serialize};
11
12/// The three mandatory parts of a gate refusal: rule | violation |
13/// compliant alternative (three-part refusal).
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
16pub struct GateRefusal {
17    rule: String,
18    violation: String,
19    alternative: String,
20}
21
22impl GateRefusal {
23    pub fn new(
24        rule: impl Into<String>,
25        violation: impl Into<String>,
26        alternative: impl Into<String>,
27    ) -> Self {
28        GateRefusal {
29            rule: rule.into(),
30            violation: violation.into(),
31            alternative: alternative.into(),
32        }
33    }
34
35    pub fn rule(&self) -> &str {
36        &self.rule
37    }
38
39    pub fn violation(&self) -> &str {
40        &self.violation
41    }
42
43    pub fn alternative(&self) -> &str {
44        &self.alternative
45    }
46}