use heck::ToSnakeCase;
use quote::IdentFragment;
use std::borrow::Cow;
use std::fmt::Display;
pub struct Prefix(String);
impl Prefix {
pub fn new<'a, I: Into<Cow<'a, str>>>(prefix: I) -> Prefix {
let mut inner = prefix.into().to_string().to_snake_case();
match inner.ends_with("_") {
true => Prefix(inner),
false if inner.len() > 0 => {
inner.push('_');
Prefix(inner)
}
_ => Prefix(inner),
}
}
}
impl IdentFragment for Prefix {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
IdentFragment::fmt(&self.0, f)
}
}
impl Display for Prefix {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl From<Prefix> for String {
fn from(value: Prefix) -> Self {
value.0
}
}