@@ -28,14 +28,11 @@ use infer::Infer;
28
28
/// ```
29
29
// NOTE: we cannot statically initialize Strings with values yet, so we keep dedicated static
30
30
// fields for the static strings.
31
- #[ derive( Clone ) ]
31
+ #[ derive( Clone , Eq ) ]
32
32
pub struct Mime {
33
- pub ( crate ) essence : String ,
34
- pub ( crate ) basetype : String ,
35
- pub ( crate ) subtype : String ,
36
- pub ( crate ) static_essence : Option < & ' static str > ,
37
- pub ( crate ) static_basetype : Option < & ' static str > ,
38
- pub ( crate ) static_subtype : Option < & ' static str > ,
33
+ pub ( crate ) essence : Cow < ' static , str > ,
34
+ pub ( crate ) basetype : Cow < ' static , str > ,
35
+ pub ( crate ) subtype : Cow < ' static , str > ,
39
36
pub ( crate ) params : Option < ParamKind > ,
40
37
}
41
38
@@ -68,29 +65,17 @@ impl Mime {
68
65
/// According to the spec this method should be named `type`, but that's a reserved keyword in
69
66
/// Rust so hence prefix with `base` instead.
70
67
pub fn basetype ( & self ) -> & str {
71
- if let Some ( basetype) = self . static_basetype {
72
- & basetype
73
- } else {
74
- & self . basetype
75
- }
68
+ & self . basetype
76
69
}
77
70
78
71
/// Access the Mime's `subtype` value.
79
72
pub fn subtype ( & self ) -> & str {
80
- if let Some ( subtype) = self . static_subtype {
81
- & subtype
82
- } else {
83
- & self . subtype
84
- }
73
+ & self . subtype
85
74
}
86
75
87
76
/// Access the Mime's `essence` value.
88
77
pub fn essence ( & self ) -> & str {
89
- if let Some ( essence) = self . static_essence {
90
- & essence
91
- } else {
92
- & self . essence
93
- }
78
+ & self . essence
94
79
}
95
80
96
81
/// Get a reference to a param.
@@ -138,20 +123,6 @@ impl Mime {
138
123
}
139
124
}
140
125
141
- impl PartialEq < Mime > for Mime {
142
- fn eq ( & self , other : & Mime ) -> bool {
143
- let left = match self . static_essence {
144
- Some ( essence) => essence,
145
- None => & self . essence ,
146
- } ;
147
- let right = match other. static_essence {
148
- Some ( essence) => essence,
149
- None => & other. essence ,
150
- } ;
151
- left == right
152
- }
153
- }
154
-
155
126
impl Display for Mime {
156
127
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
157
128
parse:: format ( self , f)
@@ -160,11 +131,7 @@ impl Display for Mime {
160
131
161
132
impl Debug for Mime {
162
133
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
163
- if let Some ( essence) = self . static_essence {
164
- Debug :: fmt ( essence, f)
165
- } else {
166
- Debug :: fmt ( & self . essence , f)
167
- }
134
+ Debug :: fmt ( & self . essence , f)
168
135
}
169
136
}
170
137
@@ -196,6 +163,13 @@ impl ToHeaderValues for Mime {
196
163
Ok ( header. to_header_values ( ) . unwrap ( ) )
197
164
}
198
165
}
166
+
167
+ impl PartialEq < Mime > for Mime {
168
+ fn eq ( & self , other : & Mime ) -> bool {
169
+ self . essence == other. essence
170
+ }
171
+ }
172
+
199
173
/// A parameter name.
200
174
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
201
175
pub struct ParamName ( Cow < ' static , str > ) ;
0 commit comments