mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-22 11:13:09 +02:00
implement FromStr instead of just from_str
This commit is contained in:
parent
cf3a053a0e
commit
7956f6a34b
1 changed files with 23 additions and 23 deletions
|
@ -22,7 +22,29 @@ pub(super) enum TagInner {
|
|||
pub const INVALID_TAG_CHARACTERS: &str = "+-*/(<>^! %=~";
|
||||
|
||||
impl Tag {
|
||||
pub fn from_str(value: &str) -> Result<Tag, anyhow::Error> {
|
||||
/// 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<Tag, anyhow::Error> {
|
||||
fn err(value: &str) -> Result<Tag, anyhow::Error> {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue