11//! Helper tools for intra doc links.
22
3- const TYPES : ( [ & str ; 9 ] , [ & str ; 0 ] ) =
4- ( [ "type" , "struct" , "enum" , "mod" , "trait" , "union" , "module" , "prim" , "primitive" ] , [ ] ) ;
5- const VALUES : ( [ & str ; 8 ] , [ & str ; 1 ] ) =
6- ( [ "value" , "function" , "fn" , "method" , "const" , "static" , "mod" , "module" ] , [ "()" ] ) ;
7- const MACROS : ( [ & str ; 2 ] , [ & str ; 1 ] ) = ( [ "macro" , "derive" ] , [ "!" ] ) ;
3+ const TYPES : ( & [ & str ] , & [ & str ] ) =
4+ ( & [ "type" , "struct" , "enum" , "mod" , "trait" , "union" , "module" , "prim" , "primitive" ] , & [ ] ) ;
5+ const VALUES : ( & [ & str ] , & [ & str ] ) =
6+ ( & [ "value" , "function" , "fn" , "method" , "const" , "static" , "mod" , "module" ] , & [ "()" ] ) ;
7+ const MACROS : ( & [ & str ] , & [ & str ] ) = ( & [ "macro" , "derive" ] , & [ "!" ] ) ;
88
99/// Extract the specified namespace from an intra-doc-link if one exists.
1010///
@@ -17,42 +17,38 @@ pub(super) fn parse_intra_doc_link(s: &str) -> (&str, Option<hir::Namespace>) {
1717 let s = s. trim_matches ( '`' ) ;
1818
1919 [
20- ( hir:: Namespace :: Types , ( TYPES . 0 . iter ( ) , TYPES . 1 . iter ( ) ) ) ,
21- ( hir:: Namespace :: Values , ( VALUES . 0 . iter ( ) , VALUES . 1 . iter ( ) ) ) ,
22- ( hir:: Namespace :: Macros , ( MACROS . 0 . iter ( ) , MACROS . 1 . iter ( ) ) ) ,
20+ ( hir:: Namespace :: Types , TYPES ) ,
21+ ( hir:: Namespace :: Values , VALUES ) ,
22+ ( hir:: Namespace :: Macros , MACROS ) ,
2323 ]
2424 . into_iter ( )
25- . find_map ( |( ns, ( mut prefixes, mut suffixes) ) | {
26- if let Some ( prefix) = prefixes. find ( |& & prefix| {
25+ . find_map ( |( ns, ( prefixes, suffixes) ) | {
26+ if let Some ( prefix) = prefixes. iter ( ) . find ( |& & prefix| {
2727 s. starts_with ( prefix)
2828 && s. chars ( ) . nth ( prefix. len ( ) ) . map_or ( false , |c| c == '@' || c == ' ' )
2929 } ) {
3030 Some ( ( & s[ prefix. len ( ) + 1 ..] , ns) )
3131 } else {
32- suffixes. find_map ( |& suffix| s. strip_suffix ( suffix) . zip ( Some ( ns) ) )
32+ suffixes. iter ( ) . find_map ( |& suffix| s. strip_suffix ( suffix) . zip ( Some ( ns) ) )
3333 }
3434 } )
3535 . map_or ( ( s, None ) , |( s, ns) | ( s, Some ( ns) ) )
3636}
3737
3838pub ( super ) fn strip_prefixes_suffixes ( s : & str ) -> & str {
39- [
40- ( TYPES . 0 . iter ( ) , TYPES . 1 . iter ( ) ) ,
41- ( VALUES . 0 . iter ( ) , VALUES . 1 . iter ( ) ) ,
42- ( MACROS . 0 . iter ( ) , MACROS . 1 . iter ( ) ) ,
43- ]
44- . into_iter ( )
45- . find_map ( |( mut prefixes, mut suffixes) | {
46- if let Some ( prefix) = prefixes. find ( |& & prefix| {
47- s. starts_with ( prefix)
48- && s. chars ( ) . nth ( prefix. len ( ) ) . map_or ( false , |c| c == '@' || c == ' ' )
49- } ) {
50- Some ( & s[ prefix. len ( ) + 1 ..] )
51- } else {
52- suffixes. find_map ( |& suffix| s. strip_suffix ( suffix) )
53- }
54- } )
55- . unwrap_or ( s)
39+ [ TYPES , VALUES , MACROS ]
40+ . into_iter ( )
41+ . find_map ( |( prefixes, suffixes) | {
42+ if let Some ( prefix) = prefixes. iter ( ) . find ( |& & prefix| {
43+ s. starts_with ( prefix)
44+ && s. chars ( ) . nth ( prefix. len ( ) ) . map_or ( false , |c| c == '@' || c == ' ' )
45+ } ) {
46+ Some ( & s[ prefix. len ( ) + 1 ..] )
47+ } else {
48+ suffixes. iter ( ) . find_map ( |& suffix| s. strip_suffix ( suffix) )
49+ }
50+ } )
51+ . unwrap_or ( s)
5652}
5753
5854#[ cfg( test) ]
0 commit comments