fallow_mutation/
operator.rs1use serde::Serialize;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
10#[serde(rename_all = "kebab-case")]
11pub enum Operator {
12 ArithmeticOperator,
14 RelationalOperator,
16 LogicalOperator,
18 NegateCondition,
20 UnaryOperator,
22 UpdateOperator,
24 RemovedCall,
26 ReturnValue,
28 BooleanLiteral,
30 StringLiteral,
32 OptionalChaining,
34 RegexLiteral,
38}
39
40impl Operator {
41 pub const ALL: [Self; 12] = [
43 Self::ArithmeticOperator,
44 Self::RelationalOperator,
45 Self::LogicalOperator,
46 Self::NegateCondition,
47 Self::UnaryOperator,
48 Self::UpdateOperator,
49 Self::RemovedCall,
50 Self::ReturnValue,
51 Self::BooleanLiteral,
52 Self::StringLiteral,
53 Self::OptionalChaining,
54 Self::RegexLiteral,
55 ];
56
57 pub const fn as_str(self) -> &'static str {
59 match self {
60 Self::ArithmeticOperator => "arithmetic-operator",
61 Self::RelationalOperator => "relational-operator",
62 Self::LogicalOperator => "logical-operator",
63 Self::NegateCondition => "negate-condition",
64 Self::UnaryOperator => "unary-operator",
65 Self::UpdateOperator => "update-operator",
66 Self::RemovedCall => "removed-call",
67 Self::ReturnValue => "return-value",
68 Self::BooleanLiteral => "boolean-literal",
69 Self::StringLiteral => "string-literal",
70 Self::OptionalChaining => "optional-chaining",
71 Self::RegexLiteral => "regex-literal",
72 }
73 }
74
75 pub fn from_name(name: &str) -> Option<Self> {
77 Self::ALL
78 .into_iter()
79 .find(|operator| operator.as_str() == name)
80 }
81}
82
83impl std::fmt::Display for Operator {
84 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 f.write_str(self.as_str())
86 }
87}