From c75a38f6152fffcdb7b044231f7c65da957ece25 Mon Sep 17 00:00:00 2001 From: John Turner Date: Tue, 18 Nov 2025 04:15:53 +0000 Subject: allow slot to be only :* := :slot/sub= or :slot --- src/atom/mod.rs | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'src/atom/mod.rs') diff --git a/src/atom/mod.rs b/src/atom/mod.rs index 0378a8d..6251e35 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -79,11 +79,17 @@ pub enum SlotOperator { #[derive(Clone, Debug, PartialEq, Eq, Get)] pub struct SlotName(#[get(method = "name", kind = "deref")] String); -#[derive(Clone, Debug, PartialEq, Eq, Get)] -pub struct Slot { - primary: Option, - sub: Option, - operator: Option, +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum Slot { + Wildcard, + Equal { + primary: Option, + sub: Option, + }, + Name { + primary: SlotName, + sub: Option, + }, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -575,19 +581,29 @@ impl fmt::Display for SlotName { impl fmt::Display for Slot { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(slot) = self.primary.as_ref() { - write!(f, "{slot}")?; - } + match self { + Self::Wildcard => write!(f, "*"), + Self::Equal { primary, sub } => { + if let Some(primary) = primary { + write!(f, "{primary}")?; + } - if let Some(sub) = self.sub.as_ref() { - write!(f, "/{sub}")?; - } + if let Some(sub) = sub { + write!(f, "/{sub}")?; + } - if let Some(operator) = self.operator.as_ref() { - write!(f, "{operator}")?; - } + write!(f, "=") + } + Self::Name { primary, sub } => { + write!(f, "{primary}")?; - Ok(()) + if let Some(sub) = sub { + write!(f, "/{sub}")?; + } + + Ok(()) + } + } } } -- cgit v1.2.3