graphcal_compiler/syntax/
attribute.rs1use thiserror::Error;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum AttributeName {
8 Assumes,
9 ExpectedFail,
10 Hidden,
11 Lazy,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, Error)]
16#[error("unknown attribute `{raw}`")]
17pub struct UnknownAttributeName {
18 raw: String,
19}
20
21impl UnknownAttributeName {
22 #[must_use]
24 pub fn new(raw: impl Into<String>) -> Self {
25 Self { raw: raw.into() }
26 }
27
28 #[must_use]
30 pub fn raw(&self) -> &str {
31 &self.raw
32 }
33
34 #[must_use]
36 pub fn into_raw(self) -> String {
37 self.raw
38 }
39}
40
41impl std::str::FromStr for AttributeName {
42 type Err = UnknownAttributeName;
43
44 fn from_str(s: &str) -> Result<Self, Self::Err> {
45 match s {
46 "assumes" => Ok(Self::Assumes),
47 "expected_fail" => Ok(Self::ExpectedFail),
48 "hidden" => Ok(Self::Hidden),
49 "lazy" => Ok(Self::Lazy),
50 _ => Err(UnknownAttributeName::new(s)),
51 }
52 }
53}