Skip to main content

visual_rubric/
typed_strings.rs

1use std::fmt;
2use std::ops::Deref;
3
4use serde::{Deserialize, Deserializer, Serialize};
5
6/// Validated rubric verdict status.
7#[derive(Clone, Debug, Serialize, PartialEq, Eq, Hash)]
8#[serde(transparent)]
9pub struct RubricVerdictStatus(String);
10
11impl RubricVerdictStatus {
12    /// Returns the status as the JSON wire value.
13    #[must_use]
14    pub fn as_str(&self) -> &str {
15        self.0.as_str()
16    }
17
18    /// Returns true when the status is `pass`.
19    #[must_use]
20    pub fn is_pass(&self) -> bool {
21        self.0 == "pass"
22    }
23}
24
25impl<'de> Deserialize<'de> for RubricVerdictStatus {
26    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
27    where
28        D: Deserializer<'de>,
29    {
30        let value = String::deserialize(deserializer)?;
31        match value.as_str() {
32            "pass" | "fail" => Ok(Self(value)),
33            _ => Err(serde::de::Error::custom(format!(
34                "unknown rubric verdict status {value:?}"
35            ))),
36        }
37    }
38}
39
40impl From<&str> for RubricVerdictStatus {
41    fn from(value: &str) -> Self {
42        Self(value.to_owned())
43    }
44}
45
46impl From<String> for RubricVerdictStatus {
47    fn from(value: String) -> Self {
48        Self(value)
49    }
50}
51
52impl Deref for RubricVerdictStatus {
53    type Target = str;
54
55    fn deref(&self) -> &Self::Target {
56        self.as_str()
57    }
58}
59
60impl fmt::Display for RubricVerdictStatus {
61    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62        f.write_str(self.as_str())
63    }
64}
65
66impl PartialEq<&str> for RubricVerdictStatus {
67    fn eq(&self, other: &&str) -> bool {
68        self.as_str() == *other
69    }
70}
71
72/// Validated Codex ACP reasoning effort value.
73#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
74#[serde(transparent)]
75pub struct RubricEffort(String);
76
77impl RubricEffort {
78    /// Returns the effort as the Codex ACP wire value.
79    #[must_use]
80    pub fn as_str(&self) -> &str {
81        self.0.as_str()
82    }
83}
84
85impl From<&str> for RubricEffort {
86    fn from(value: &str) -> Self {
87        Self(value.to_owned())
88    }
89}
90
91impl From<String> for RubricEffort {
92    fn from(value: String) -> Self {
93        Self(value)
94    }
95}
96
97impl Deref for RubricEffort {
98    type Target = str;
99
100    fn deref(&self) -> &Self::Target {
101        self.as_str()
102    }
103}
104
105impl fmt::Display for RubricEffort {
106    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107        f.write_str(self.as_str())
108    }
109}