standout_render/style/
value.rs1use console::Style;
4
5#[derive(Debug, Clone)]
26pub enum StyleValue {
27 Concrete(Style),
29 Alias(String),
31}
32
33impl From<Style> for StyleValue {
34 fn from(style: Style) -> Self {
35 StyleValue::Concrete(style)
36 }
37}
38
39impl From<&str> for StyleValue {
40 fn from(name: &str) -> Self {
41 StyleValue::Alias(name.to_string())
42 }
43}
44
45impl From<String> for StyleValue {
46 fn from(name: String) -> Self {
47 StyleValue::Alias(name)
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_style_value_from_style() {
57 let value: StyleValue = Style::new().bold().into();
58 assert!(matches!(value, StyleValue::Concrete(_)));
59 }
60
61 #[test]
62 fn test_style_value_from_str() {
63 let value: StyleValue = "target".into();
64 match value {
65 StyleValue::Alias(s) => assert_eq!(s, "target"),
66 _ => panic!("Expected Alias"),
67 }
68 }
69
70 #[test]
71 fn test_style_value_from_string() {
72 let value: StyleValue = String::from("target").into();
73 match value {
74 StyleValue::Alias(s) => assert_eq!(s, "target"),
75 _ => panic!("Expected Alias"),
76 }
77 }
78}