@@ -28,14 +28,11 @@ use infer::Infer;
2828/// ```
2929// NOTE: we cannot statically initialize Strings with values yet, so we keep dedicated static
3030// fields for the static strings.
31- #[ derive( Clone ) ]
31+ #[ derive( Clone , Eq ) ]
3232pub 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 > ,
3936 pub ( crate ) params : Option < ParamKind > ,
4037}
4138
@@ -68,29 +65,17 @@ impl Mime {
6865 /// According to the spec this method should be named `type`, but that's a reserved keyword in
6966 /// Rust so hence prefix with `base` instead.
7067 pub fn basetype ( & self ) -> & str {
71- if let Some ( basetype) = self . static_basetype {
72- & basetype
73- } else {
74- & self . basetype
75- }
68+ & self . basetype
7669 }
7770
7871 /// Access the Mime's `subtype` value.
7972 pub fn subtype ( & self ) -> & str {
80- if let Some ( subtype) = self . static_subtype {
81- & subtype
82- } else {
83- & self . subtype
84- }
73+ & self . subtype
8574 }
8675
8776 /// Access the Mime's `essence` value.
8877 pub fn essence ( & self ) -> & str {
89- if let Some ( essence) = self . static_essence {
90- & essence
91- } else {
92- & self . essence
93- }
78+ & self . essence
9479 }
9580
9681 /// Get a reference to a param.
@@ -138,20 +123,6 @@ impl Mime {
138123 }
139124}
140125
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-
155126impl Display for Mime {
156127 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
157128 parse:: format ( self , f)
@@ -160,11 +131,7 @@ impl Display for Mime {
160131
161132impl Debug for Mime {
162133 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)
168135 }
169136}
170137
@@ -196,6 +163,13 @@ impl ToHeaderValues for Mime {
196163 Ok ( header. to_header_values ( ) . unwrap ( ) )
197164 }
198165}
166+
167+ impl PartialEq < Mime > for Mime {
168+ fn eq ( & self , other : & Mime ) -> bool {
169+ self . essence == other. essence
170+ }
171+ }
172+
199173/// A parameter name.
200174#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
201175pub struct ParamName ( Cow < ' static , str > ) ;
0 commit comments