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 RemovedChainLink,
41}
42
43impl Operator {
44 pub const ALL: [Self; 13] = [
46 Self::ArithmeticOperator,
47 Self::RelationalOperator,
48 Self::LogicalOperator,
49 Self::NegateCondition,
50 Self::UnaryOperator,
51 Self::UpdateOperator,
52 Self::RemovedCall,
53 Self::ReturnValue,
54 Self::BooleanLiteral,
55 Self::StringLiteral,
56 Self::OptionalChaining,
57 Self::RegexLiteral,
58 Self::RemovedChainLink,
59 ];
60
61 pub const fn as_str(self) -> &'static str {
63 match self {
64 Self::ArithmeticOperator => "arithmetic-operator",
65 Self::RelationalOperator => "relational-operator",
66 Self::LogicalOperator => "logical-operator",
67 Self::NegateCondition => "negate-condition",
68 Self::UnaryOperator => "unary-operator",
69 Self::UpdateOperator => "update-operator",
70 Self::RemovedCall => "removed-call",
71 Self::ReturnValue => "return-value",
72 Self::BooleanLiteral => "boolean-literal",
73 Self::StringLiteral => "string-literal",
74 Self::OptionalChaining => "optional-chaining",
75 Self::RegexLiteral => "regex-literal",
76 Self::RemovedChainLink => "removed-chain-link",
77 }
78 }
79
80 pub fn from_name(name: &str) -> Option<Self> {
82 Self::ALL
83 .into_iter()
84 .find(|operator| operator.as_str() == name)
85 }
86}
87
88impl std::fmt::Display for Operator {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 f.write_str(self.as_str())
91 }
92}