hydrus_api/wrapper/
tag.rs1#[derive(Clone, Debug, PartialOrd, PartialEq)]
2pub struct Tag {
3 pub negated: bool,
4 pub name: String,
5 pub namespace: Option<String>,
6}
7
8impl Eq for Tag {}
9
10impl<S> From<S> for Tag
11where
12 S: AsRef<str>,
13{
14 fn from(value: S) -> Self {
15 let mut value = value.as_ref().trim();
16 let negated = value.starts_with("-");
17 value = value.trim_start_matches("-");
18 if let Some((namespace, tag)) = value.split_once(":") {
19 Self {
20 negated,
21 namespace: Some(namespace.to_string()),
22 name: tag.to_string(),
23 }
24 } else {
25 Self {
26 negated,
27 name: value.to_string(),
28 namespace: None,
29 }
30 }
31 }
32}
33
34impl ToString for Tag {
35 fn to_string(&self) -> String {
36 let negation = if self.negated { "-" } else { "" };
37 if let Some(namespace) = &self.namespace {
38 format!("{}{}:{}", negation, namespace, self.name)
39 } else {
40 format!("{}{}", negation, self.name)
41 }
42 }
43}