plotnik_bytecode/type_system/
arity.rs

1//! Structural arity definitions.
2//!
3//! Arity tracks whether an expression matches one or many node positions.
4
5/// Structural arity - whether an expression matches one or many positions.
6#[derive(Copy, Clone, PartialEq, Eq, Debug)]
7pub enum Arity {
8    /// Exactly one node position.
9    One,
10    /// Multiple sequential positions.
11    Many,
12}
13
14impl Arity {
15    /// Combine arities: Many wins.
16    ///
17    /// When combining expressions, if either has Many arity,
18    /// the result has Many arity.
19    pub fn combine(self, other: Self) -> Self {
20        if self == Self::One && other == Self::One {
21            return Self::One;
22        }
23        Self::Many
24    }
25
26    /// Check if this is singular arity.
27    pub fn is_one(self) -> bool {
28        self == Self::One
29    }
30
31    /// Check if this is plural arity.
32    pub fn is_many(self) -> bool {
33        self == Self::Many
34    }
35}