From 7956f6a34b85400eb5b8a418392297301ceee41f Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sat, 5 Jun 2021 21:18:49 -0400 Subject: [PATCH] implement FromStr instead of just from_str --- taskchampion/src/task/tag.rs | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/taskchampion/src/task/tag.rs b/taskchampion/src/task/tag.rs index 7554a57dd..d3a4842e7 100644 --- a/taskchampion/src/task/tag.rs +++ b/taskchampion/src/task/tag.rs @@ -22,7 +22,29 @@ pub(super) enum TagInner { pub const INVALID_TAG_CHARACTERS: &str = "+-*/(<>^! %=~"; impl Tag { - pub fn from_str(value: &str) -> Result { + /// True if this tag is a synthetic tag + pub fn is_synthetic(&self) -> bool { + matches!(self.0, TagInner::Synthetic(_)) + } + + /// True if this tag is a user-provided tag (not synthetic) + pub fn is_user(&self) -> bool { + matches!(self.0, TagInner::User(_)) + } + + pub(super) fn inner(&self) -> &TagInner { + &self.0 + } + + pub(super) fn from_inner(inner: TagInner) -> Self { + Self(inner) + } +} + +impl FromStr for Tag { + type Err = anyhow::Error; + + fn from_str(value: &str) -> Result { fn err(value: &str) -> Result { anyhow::bail!("invalid tag {:?}", value) } @@ -52,28 +74,6 @@ impl Tag { } Ok(Self(TagInner::User(String::from(value)))) } - - /// True if this tag is a synthetic tag - pub fn is_synthetic(&self) -> bool { - if let TagInner::Synthetic(_) = self.0 { - true - } else { - false - } - } - - /// True if this tag is a user-provided tag (not synthetic) - pub fn is_user(&self) -> bool { - !self.is_synthetic() - } - - pub(super) fn inner(&self) -> &TagInner { - &self.0 - } - - pub(super) fn from_inner(inner: TagInner) -> Self { - Self(inner) - } } impl TryFrom<&str> for Tag {