use proc_macro2::{Ident, Span};
use syn::{Lit, LitStr};
pub(super) trait ToLitStr {
fn to_lit_str(&self) -> LitStr;
}
impl ToLitStr for Ident {
fn to_lit_str(&self) -> LitStr {
LitStr::new(&self.to_string(), self.span())
}
}
impl ToLitStr for String {
fn to_lit_str(&self) -> LitStr {
LitStr::new(self, Span::call_site())
}
}
impl ToLitStr for &str {
fn to_lit_str(&self) -> LitStr {
LitStr::new(self, Span::call_site())
}
}
pub(crate) trait ExpectLit {
fn expect_str(self) -> syn::Result<LitStr>;
}
impl ExpectLit for Lit {
fn expect_str(self) -> syn::Result<LitStr> {
match self {
Self::Str(str) => Ok(str),
_ => Err(syn::Error::new(self.span(), "Expected string literal"))
}
}
}