File tree 1 file changed +3
-6
lines changed
1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,12 @@ pub struct Registry {
10
10
11
11
impl Registry {
12
12
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 ( ) }
14
14
}
15
15
16
16
/// This will panic if an invalid error code is passed in
17
17
pub fn find_description ( & self , code : & str ) -> Option < & ' static str > {
18
- self . try_find_description ( code) . unwrap ( )
18
+ self . long_descriptions [ code]
19
19
}
20
20
/// Returns `InvalidErrorCode` if the code requested does not exist in the
21
21
/// registry. Otherwise, returns an `Option` where `None` means the error
@@ -24,9 +24,6 @@ impl Registry {
24
24
& self ,
25
25
code : & str ,
26
26
) -> 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 )
31
28
}
32
29
}
You can’t perform that action at this time.
0 commit comments