use crate::*;
impl Visibility {
pub(crate) fn to_token_stream(self) -> TokenStream2 {
match self {
Visibility::Public => quote! { pub },
Visibility::PublicCrate => quote! { pub(crate) },
Visibility::PublicSuper => quote! { pub(super) },
Visibility::Private => quote! {},
}
}
}
impl Display for Visibility {
#[inline(always)]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s: &str = match self {
Visibility::Public => PUB,
Visibility::PublicCrate => PUB_CRATE,
Visibility::PublicSuper => PUB_SUPER,
Visibility::Private => PRIVATE,
};
write!(f, "{s}")
}
}
impl std::str::FromStr for Visibility {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
PUB => Ok(Visibility::Public),
CRATE | PUB_CRATE => Ok(Visibility::PublicCrate),
SUPER | PUB_SUPER => Ok(Visibility::PublicSuper),
PRIVATE => Ok(Visibility::Private),
_ => Err(format!("Unknown visibility modifier: {s}")),
}
}
}