diff --git a/codex-rs/execpolicy2/src/policy.rs b/codex-rs/execpolicy2/src/policy.rs index 34ffce7890..1e04379a40 100644 --- a/codex-rs/execpolicy2/src/policy.rs +++ b/codex-rs/execpolicy2/src/policy.rs @@ -10,22 +10,6 @@ pub struct Policy { rules_by_program: MultiMap, } -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub enum Evaluation { - NoMatch, - Match { - decision: Decision, - matched_rules: Vec, - }, -} - -impl Evaluation { - pub fn is_match(&self) -> bool { - matches!(self, Self::Match { .. }) - } -} - impl Policy { pub fn new(rules_by_program: MultiMap) -> Self { Self { rules_by_program } @@ -56,6 +40,22 @@ impl Policy { } } +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum Evaluation { + NoMatch, + Match { + decision: Decision, + matched_rules: Vec, + }, +} + +impl Evaluation { + pub fn is_match(&self) -> bool { + matches!(self, Self::Match { .. }) + } +} + impl std::fmt::Display for Evaluation { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { diff --git a/codex-rs/execpolicy2/src/rule.rs b/codex-rs/execpolicy2/src/rule.rs index ce975afd47..b5c4bf2d01 100644 --- a/codex-rs/execpolicy2/src/rule.rs +++ b/codex-rs/execpolicy2/src/rule.rs @@ -66,29 +66,6 @@ impl std::fmt::Display for PrefixPattern { } } -#[derive(Clone, Debug)] -pub enum Rule { - Prefix(PrefixRule), -} - -impl std::fmt::Display for Rule { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Prefix(rule) => write!( - f, - "prefix_rule(pattern = {}, decision = {})", - rule.pattern, rule.decision - ), - } - } -} - -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct PrefixRule { - pub pattern: PrefixPattern, - pub decision: Decision, -} - #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum RuleMatch { @@ -120,28 +97,10 @@ impl std::fmt::Display for RuleMatch { } } -impl Rule { - pub fn program(&self) -> &str { - match self { - Self::Prefix(rule) => rule.pattern.first.as_ref(), - } - } - - pub fn matches(&self, cmd: &[String]) -> Option { - match self { - Self::Prefix(rule) => rule.matches(cmd), - } - } - - pub fn validate_examples( - &self, - matches: &[Vec], - not_matches: &[Vec], - ) -> Result<()> { - match self { - Self::Prefix(rule) => rule.validate_examples(matches, not_matches), - } - } +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct PrefixRule { + pub pattern: PrefixPattern, + pub decision: Decision, } impl PrefixRule { @@ -187,6 +146,47 @@ impl PrefixRule { } } +#[derive(Clone, Debug)] +pub enum Rule { + Prefix(PrefixRule), +} + +impl Rule { + pub fn program(&self) -> &str { + match self { + Self::Prefix(rule) => rule.pattern.first.as_ref(), + } + } + + pub fn matches(&self, cmd: &[String]) -> Option { + match self { + Self::Prefix(rule) => rule.matches(cmd), + } + } + + pub fn validate_examples( + &self, + matches: &[Vec], + not_matches: &[Vec], + ) -> Result<()> { + match self { + Self::Prefix(rule) => rule.validate_examples(matches, not_matches), + } + } +} + +impl std::fmt::Display for Rule { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Prefix(rule) => write!( + f, + "prefix_rule(pattern = {}, decision = {})", + rule.pattern, rule.decision + ), + } + } +} + fn join_command(command: &[String]) -> String { try_join(command.iter().map(String::as_str)) .unwrap_or_else(|_| "unable to render example".to_string())