Skip to main content

moxy_token/
spacing.rs

1/// Whether a Punct is followed immediately by another Punct or followed by another token or whitespace.
2#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "lowercase"))]
4pub enum Spacing {
5    #[default]
6    Alone,
7    Joint,
8}
9
10impl Spacing {
11    #[inline]
12    pub fn is_alone(&self) -> bool {
13        matches!(self, Self::Alone)
14    }
15
16    #[inline]
17    pub fn is_joint(&self) -> bool {
18        matches!(self, Self::Joint)
19    }
20
21    #[inline]
22    pub fn as_str(&self) -> &'static str {
23        match self {
24            Self::Alone => "alone",
25            Self::Joint => "joint",
26        }
27    }
28}
29
30impl std::fmt::Display for Spacing {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        f.write_str(self.as_str())
33    }
34}