1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use super::*;
#[derive(Debug, Clone)]
pub enum MaybeArbitrary {
Standard(String),
Arbitrary(String),
}
impl Display for MaybeArbitrary {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Standard(s) => write!(f, "{}", s),
Self::Arbitrary(s) => write!(f, "[{}]", s),
}
}
}
impl MaybeArbitrary {
pub fn parser(
id: &'static str,
check_valid: &'static impl Fn(&str) -> bool,
) -> impl Fn(&[&str], &TailwindArbitrary) -> Result<Self> {
move |pattern: &[&str], arbitrary: &TailwindArbitrary| match pattern {
[] => Self::parse_arbitrary(arbitrary),
_ => Self::parse_standard(pattern, id, check_valid),
}
}
pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
debug_assert!(arbitrary.is_some());
Ok(Self::Arbitrary(arbitrary.to_string()))
}
pub fn parse_standard(pattern: &[&str], id: &str, checker: &'static impl Fn(&str) -> bool) -> Result<Self> {
let keyword = pattern.join("-");
debug_assert!(checker(&keyword), "{} does not a valid value of {}", keyword, id);
Ok(Self::Standard(keyword))
}
pub fn get_properties(&self) -> &str {
match self {
Self::Standard(s) => s.as_str(),
Self::Arbitrary(s) => s.as_str(),
}
}
}