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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use crate::prelude::{Style, Value};
use crate::vdom::Listener;
use std::fmt::{self, Debug};
pub enum AttributeValue<MSG> {
FunctionCall(Value),
Simple(Value),
Style(Vec<Style>),
EventListener(Listener<MSG>),
Empty,
}
impl<MSG> Clone for AttributeValue<MSG> {
fn clone(&self) -> Self {
match self {
AttributeValue::FunctionCall(this) => {
AttributeValue::FunctionCall(this.clone())
}
AttributeValue::Simple(this) => {
AttributeValue::Simple(this.clone())
}
AttributeValue::Style(this) => AttributeValue::Style(this.clone()),
AttributeValue::EventListener(this) => {
AttributeValue::EventListener(this.clone())
}
AttributeValue::Empty => AttributeValue::Empty,
}
}
}
impl<MSG> Debug for AttributeValue<MSG> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AttributeValue::FunctionCall(this) => this.fmt(f),
AttributeValue::Simple(this) => this.fmt(f),
AttributeValue::Style(this) => this.fmt(f),
AttributeValue::EventListener(this) => this.fmt(f),
AttributeValue::Empty => write!(f, "Empty"),
}
}
}
impl<MSG> PartialEq for AttributeValue<MSG> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
AttributeValue::FunctionCall(this),
AttributeValue::FunctionCall(other),
) => this == other,
(AttributeValue::Simple(this), AttributeValue::Simple(other)) => {
this == other
}
(AttributeValue::Style(this), AttributeValue::Style(other)) => {
this == other
}
(
AttributeValue::EventListener(this),
AttributeValue::EventListener(other),
) => this == other,
(AttributeValue::Empty, AttributeValue::Empty) => true,
(_, _) => false,
}
}
}
impl<MSG> AttributeValue<MSG> {
pub fn from_styles(styles: impl IntoIterator<Item = Style>) -> Self {
AttributeValue::Style(styles.into_iter().collect())
}
pub fn from_value(value: Value) -> Self {
AttributeValue::Simple(value)
}
pub fn function_call(value: Value) -> Self {
AttributeValue::FunctionCall(value)
}
pub fn get_simple(&self) -> Option<&Value> {
match self {
AttributeValue::Simple(v) => Some(v),
_ => None,
}
}
pub fn get_function_call_value(&self) -> Option<&Value> {
match self {
AttributeValue::FunctionCall(v) => Some(v),
_ => None,
}
}
pub fn is_style(&self) -> bool {
matches!(self, AttributeValue::Style(_))
}
pub fn as_event_listener(&self) -> Option<&Listener<MSG>> {
match self {
AttributeValue::EventListener(cb) => Some(cb),
_ => None,
}
}
pub fn as_style(&self) -> Option<&Vec<Style>> {
match self {
AttributeValue::Style(styles) => Some(styles),
_ => None,
}
}
pub fn is_function_call(&self) -> bool {
matches!(self, AttributeValue::FunctionCall(_))
}
pub fn is_empty(&self) -> bool {
matches!(self, AttributeValue::Empty)
}
}