@@ -41,7 +41,7 @@ pub trait ErrorDiagnostic: error::Error + 'static {
4141 fn kind ( & self ) -> Self :: Kind ;
4242
4343 /// Provides a string to identify responsible service
44- fn service ( & self ) -> Option < ByteString > {
44+ fn service ( & self ) -> Option < & ' static str > {
4545 None
4646 }
4747
@@ -77,7 +77,7 @@ pub trait ErrorInfo {
7777
7878 fn error_signature ( & self ) -> ByteString ;
7979
80- fn service ( & self ) -> Option < ByteString > ;
80+ fn service ( & self ) -> Option < & ' static str > ;
8181
8282 fn signature ( & self ) -> & ' static str ;
8383
@@ -95,14 +95,14 @@ trait Traversable<K>: ErrorDiagnostic<Kind = K> {
9595pub struct Error < E > {
9696 #[ source]
9797 error : E ,
98- service : Option < ByteString > ,
98+ service : Option < & ' static str > ,
9999 location : & ' static Location < ' static > ,
100100}
101101
102102impl < E > Error < E > {
103103 pub const fn new (
104104 error : E ,
105- service : Option < ByteString > ,
105+ service : Option < & ' static str > ,
106106 location : & ' static Location < ' static > ,
107107 ) -> Self {
108108 Self {
@@ -113,7 +113,7 @@ impl<E> Error<E> {
113113 }
114114
115115 /// Set response service
116- pub fn set_service ( mut self , name : ByteString ) -> Self {
116+ pub fn set_service ( mut self , name : & ' static str ) -> Self {
117117 self . service = Some ( name) ;
118118 self
119119 }
@@ -145,6 +145,8 @@ impl<E> From<E> for Error<E> {
145145 }
146146}
147147
148+ impl < E > Eq for Error < E > where E : Eq { }
149+
148150impl < E > PartialEq for Error < E >
149151where
150152 E : PartialEq ,
@@ -154,7 +156,14 @@ where
154156 }
155157}
156158
157- impl < E > Eq for Error < E > where E : Eq { }
159+ impl < E > PartialEq < E > for Error < E >
160+ where
161+ E : PartialEq ,
162+ {
163+ fn eq ( & self , other : & E ) -> bool {
164+ self . error . eq ( other)
165+ }
166+ }
158167
159168impl < E > ops:: Deref for Error < E > {
160169 type Target = E ;
@@ -174,8 +183,12 @@ where
174183 self . error . kind ( )
175184 }
176185
177- fn service ( & self ) -> Option < ByteString > {
178- self . service . clone ( )
186+ fn service ( & self ) -> Option < & ' static str > {
187+ if self . service . is_some ( ) {
188+ self . service
189+ } else {
190+ self . error . service ( )
191+ }
179192 }
180193
181194 fn signature ( & self ) -> & ' static str {
@@ -229,8 +242,8 @@ where
229242 fn from ( err : Error < E > ) -> Self {
230243 Self {
231244 error : Arc :: new ( ErrorChainWrapper {
245+ service : err. service ( ) ,
232246 error : err. error ,
233- service : err. service ,
234247 location : err. location ,
235248 _k : PhantomData ,
236249 } ) ,
@@ -248,7 +261,7 @@ where
248261 self . error . kind ( )
249262 }
250263
251- fn service ( & self ) -> Option < ByteString > {
264+ fn service ( & self ) -> Option < & ' static str > {
252265 self . error . service ( )
253266 }
254267
@@ -270,7 +283,7 @@ where
270283struct ErrorChainWrapper < E : Sized , K > {
271284 #[ source]
272285 error : E ,
273- service : Option < ByteString > ,
286+ service : Option < & ' static str > ,
274287 location : & ' static Location < ' static > ,
275288 _k : PhantomData < K > ,
276289}
@@ -298,8 +311,8 @@ where
298311 self . error . kind ( ) . into ( )
299312 }
300313
301- fn service ( & self ) -> Option < ByteString > {
302- self . service . clone ( )
314+ fn service ( & self ) -> Option < & ' static str > {
315+ self . service
303316 }
304317
305318 fn signature ( & self ) -> & ' static str {
@@ -340,7 +353,7 @@ impl<'a, E: ErrorDiagnostic> ErrorInfo for ErrorInfoWrapper<'a, E> {
340353 ByteString :: try_from ( buf) . unwrap ( )
341354 }
342355
343- fn service ( & self ) -> Option < ByteString > {
356+ fn service ( & self ) -> Option < & ' static str > {
344357 self . inner . service ( )
345358 }
346359
@@ -405,8 +418,8 @@ mod tests {
405418 }
406419 }
407420
408- fn service ( & self ) -> Option < ByteString > {
409- Some ( ByteString :: from_static ( "test" ) )
421+ fn service ( & self ) -> Option < & ' static str > {
422+ Some ( "test" )
410423 }
411424
412425 fn signature ( & self ) -> & ' static str {
@@ -424,7 +437,7 @@ mod tests {
424437 assert_eq ! ( err. kind( ) , TestKind :: ServiceError ) ;
425438 assert_eq ! ( ( * err) . kind( ) , TestKind :: ServiceError ) ;
426439 assert_eq ! ( err. to_string( ) , "InternalServiceError" ) ;
427- assert_eq ! ( err. service( ) , Some ( ByteString :: from_static ( "test" ) ) ) ;
440+ assert_eq ! ( err. service( ) , Some ( "test" ) ) ;
428441 assert_eq ! (
429442 err,
430443 Into :: <Error <TestError >>:: into( TestError :: Service ( "409 Error" ) )
@@ -437,9 +450,12 @@ mod tests {
437450 assert_eq ! ( info. error_signature( ) , "ServiceError" ) ;
438451 assert_eq ! ( info. signature( ) , "Service-Internal" ) ;
439452 assert_eq ! ( info. description( ) , "InternalServiceError" ) ;
440- assert_eq ! ( info. service( ) , Some ( ByteString :: from_static ( "test" ) ) ) ;
453+ assert_eq ! ( info. service( ) , Some ( "test" ) ) ;
441454 } ) ;
442455
456+ let err = err. set_service ( "SVC" ) ;
457+ assert_eq ! ( err. service( ) , Some ( "SVC" ) ) ;
458+
443459 assert_eq ! (
444460 TestError :: Connect ( "" ) . kind( ) . error_type( ) ,
445461 ErrorType :: ClientError
@@ -454,10 +470,7 @@ mod tests {
454470 ) ;
455471 assert_eq ! ( TestError :: Connect ( "" ) . to_string( ) , "Connect err: " ) ;
456472 assert_eq ! ( TestError :: Disconnect . to_string( ) , "Disconnect" ) ;
457- assert_eq ! (
458- TestError :: Disconnect . service( ) ,
459- Some ( ByteString :: from_static( "test" ) )
460- ) ;
473+ assert_eq ! ( TestError :: Disconnect . service( ) , Some ( "test" ) ) ;
461474 assert ! ( TestError :: Disconnect . location( ) . is_none( ) ) ;
462475
463476 TestError :: Connect ( "" ) . traverse ( & mut |info| {
@@ -498,7 +511,7 @@ mod tests {
498511 let err: ErrorChain < TestKind > = err. into ( ) ;
499512 assert_eq ! ( err. kind( ) , TestKind :: ServiceError ) ;
500513 assert_eq ! ( err. kind( ) , TestError :: Service ( "404 Error" ) . kind( ) ) ;
501- assert_eq ! ( err. service( ) , Some ( ByteString :: from_static ( "test" ) ) ) ;
514+ assert_eq ! ( err. service( ) , Some ( "test" ) ) ;
502515 assert_eq ! ( err. signature( ) , "Service-Internal" ) ;
503516 assert_eq ! ( err. to_string( ) , "InternalServiceError" ) ;
504517 assert ! ( err. location( ) . is_some( ) ) ;
0 commit comments