/// Extract the specified namespace from an intra-doc-link if one exists.
///
/// # Examples
///
/// * `struct MyStruct` -> `Namespace::Types`
/// * `panic!` -> `Namespace::Macros`
/// * `fn@from_intra_spec` -> `Namespace::Values`
Extract the specified namespace from an intra-doc-link if one exists.
Extract the specified namespace from an intra - doc - link if one exists .
fn ns_from_intra_spec(s: &str) -> Option<hir::Namespace> {
    [
        (hir::Namespace::Types, (TYPES.0.iter(), TYPES.1.iter())),
        (hir::Namespace::Values, (VALUES.0.iter(), VALUES.1.iter())),
        (hir::Namespace::Macros, (MACROS.0.iter(), MACROS.1.iter())),
    ]
    .iter()
    .filter(|(_ns, (prefixes, suffixes))| {
        prefixes
            .clone()
            .map(|prefix| {
                s.starts_with(*prefix)
                    && s.chars()
                        .nth(prefix.len() + 1)
                        .map(|c| c == '@' || c == ' ')
                        .unwrap_or(false)
            })
            .any(|cond| cond)
            || suffixes
                .clone()
                .map(|suffix| {
                    s.starts_with(*suffix)
                        && s.chars()
                            .nth(suffix.len() + 1)
                            .map(|c| c == '@' || c == ' ')
                            .unwrap_or(false)
                })
                .any(|cond| cond)
    })
    .map(|(ns, (_, _))| *ns)
    .next()
}
fn ns_from_intra_spec ( s : & str ) -> Option < hir :: Namespace > { [ ( hir :: Namespace :: Types , ( TYPES . 0 . iter ( ) , TYPES . 1 . iter ( ) ) ) , ( hir :: Namespace :: Values , ( VALUES . 0 . iter ( ) , VALUES . 1 . iter ( ) ) ) , ( hir :: Namespace :: Macros , ( MACROS . 0 . iter ( ) , MACROS . 1 . iter ( ) ) ) , ] . iter ( ) . filter ( | ( _ns , ( prefixes , suffixes ) ) | { prefixes . clone ( ) . map ( | prefix | { s . starts_with ( * prefix ) && s . chars ( ) . nth ( prefix . len ( ) + 1 ) . map ( | c | c == '@' || c == ' ' ) . unwrap_or ( false ) } ) . any ( | cond | cond ) || suffixes . clone ( ) . map ( | suffix | { s . starts_with ( * suffix ) && s . chars ( ) . nth ( suffix . len ( ) + 1 ) . map ( | c | c == '@' || c == ' ' ) . unwrap_or ( false ) } ) . any ( | cond | cond ) } ) . map ( | ( ns , ( _ , _ ) ) | * ns ) . next ( ) }
Extract the specified namespace from an intra-doc-link if one exists.
Extract the specified namespace from an intra - doc - link if one exists .
s
&str
examples
`struct MyStruct` -> `Namespace::Types`
`panic!` -> `Namespace::Macros`
`fn@from_intra_spec` -> `Namespace::Values`
` struct MyStruct ` - > ` Namespace :: Types ` ` panic! ` - > ` Namespace :: Macros ` ` fn@from_intra_spec ` - > ` Namespace :: Values `