pub fn format_visibility(context: &RewriteContext<'_>, vis: &Visibility) -> Cow<'static, str> {
    match vis.node {
        VisibilityKind::Public => Cow::from("pub "),
        VisibilityKind::Inherited => Cow::from(""),
        VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
        VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
        VisibilityKind::Restricted { ref path, .. } => {
            let Path { ref segments, .. } = **path;
            let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
            if path.is_global() {
                segments_iter
                    .next()
                    .expect("Non-global path in pub(restricted)?");
            }
            let is_keyword = |s: &str| s == "self" || s == "super";
            let path = segments_iter.collect::<Vec<_>>().join("::");
            let in_str = if is_keyword(&path) { "" } else { "in " };

            Cow::from(format!("pub({}{}) ", in_str, path))
        }
    }
}
// Uses Cow to avoid allocating in the common cases.
Uses Cow to avoid allocating in the common cases.
Uses Cow to avoid allocating in the common cases .
pub fn format_visibility(context: &RewriteContext<'_>, vis: &Visibility) -> Cow<'static, str> {
    match vis.node {
        VisibilityKind::Public => Cow::from("pub "),
        VisibilityKind::Inherited => Cow::from(""),
        VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
        VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
        VisibilityKind::Restricted { ref path, .. } => {
            let Path { ref segments, .. } = **path;
            let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
            if path.is_global() {
                segments_iter
                    .next()
                    .expect("Non-global path in pub(restricted)?");
            }
            let is_keyword = |s: &str| s == "self" || s == "super";
            let path = segments_iter.collect::<Vec<_>>().join("::");
            let in_str = if is_keyword(&path) { "" } else { "in " };
            Cow::from(format!("pub({}{}) ", in_str, path))
        }
    }
}
pub fn format_visibility ( context : & RewriteContext < ' _ > , vis : & Visibility ) -> Cow < ' static , str > { match vis . node { VisibilityKind :: Public => Cow :: from ( " " ) , VisibilityKind :: Inherited => Cow :: from ( " " ) , VisibilityKind :: Crate ( CrateSugar :: PubCrate ) => Cow :: from ( " " ) , VisibilityKind :: Crate ( CrateSugar :: JustCrate ) => Cow :: from ( " " ) , VisibilityKind :: Restricted { ref path , .. } => { let Path { ref segments , .. } = * * path ; let mut segments_iter = segments . iter ( ) . map ( | seg | rewrite_ident ( context , seg . ident ) ) ; if path . is_global ( ) { segments_iter . next ( ) . expect ( " " ) ; } let is_keyword = | s : & str | s == " " || s == " " ; let path = segments_iter . collect :: < Vec < _ > > ( ) . join ( " " ) ; let in_str = if is_keyword ( & path ) { " " } else { " " } ; Cow :: from ( format ! ( " " in_str path ) ) } } }
Uses Cow to avoid allocating in the common cases.
Uses Cow to avoid allocating in the common cases .
context
&RewriteContext<'_>
vis
&Visibility
context
&RewriteContext<'_>
vis
&Visibility