mirror of
https://github.com/openai/codex.git
synced 2026-04-30 19:32:04 +03:00
reordering so that impl comes before def
This commit is contained in:
@@ -10,22 +10,6 @@ pub struct Policy {
|
||||
rules_by_program: MultiMap<String, Rule>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum Evaluation {
|
||||
NoMatch,
|
||||
Match {
|
||||
decision: Decision,
|
||||
matched_rules: Vec<RuleMatch>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Evaluation {
|
||||
pub fn is_match(&self) -> bool {
|
||||
matches!(self, Self::Match { .. })
|
||||
}
|
||||
}
|
||||
|
||||
impl Policy {
|
||||
pub fn new(rules_by_program: MultiMap<String, Rule>) -> 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<RuleMatch>,
|
||||
},
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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<RuleMatch> {
|
||||
match self {
|
||||
Self::Prefix(rule) => rule.matches(cmd),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_examples(
|
||||
&self,
|
||||
matches: &[Vec<String>],
|
||||
not_matches: &[Vec<String>],
|
||||
) -> 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<RuleMatch> {
|
||||
match self {
|
||||
Self::Prefix(rule) => rule.matches(cmd),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_examples(
|
||||
&self,
|
||||
matches: &[Vec<String>],
|
||||
not_matches: &[Vec<String>],
|
||||
) -> 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())
|
||||
|
||||
Reference in New Issue
Block a user