File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,12 @@ pub struct Registry {
1010
1111impl Registry {
1212 pub fn new ( long_descriptions : & [ ( & ' static str , Option < & ' static str > ) ] ) -> Registry {
13- Registry { long_descriptions : long_descriptions. iter ( ) . cloned ( ) . collect ( ) }
13+ Registry { long_descriptions : long_descriptions. iter ( ) . copied ( ) . collect ( ) }
1414 }
1515
1616 /// This will panic if an invalid error code is passed in
1717 pub fn find_description ( & self , code : & str ) -> Option < & ' static str > {
18- self . try_find_description ( code) . unwrap ( )
18+ self . long_descriptions [ code]
1919 }
2020 /// Returns `InvalidErrorCode` if the code requested does not exist in the
2121 /// registry. Otherwise, returns an `Option` where `None` means the error
@@ -24,9 +24,6 @@ impl Registry {
2424 & self ,
2525 code : & str ,
2626 ) -> Result < Option < & ' static str > , InvalidErrorCode > {
27- if !self . long_descriptions . contains_key ( code) {
28- return Err ( InvalidErrorCode ) ;
29- }
30- Ok ( * self . long_descriptions . get ( code) . unwrap ( ) )
27+ self . long_descriptions . get ( code) . copied ( ) . ok_or ( InvalidErrorCode )
3128 }
3229}
You can’t perform that action at this time.
0 commit comments