use std::ops::Deref;
use darling::FromMeta;
use quote::format_ident;
use syn::{spanned::Spanned, Lifetime, Type};
#[derive(Clone)]
pub(crate) struct RedbType(Type);
impl RedbType {
#[cfg(any(feature = "uuid", feature = "secrecy"))]
pub(super) fn new(ty: Type) -> RedbType {
RedbType(ty)
}
}
impl Deref for RedbType {
type Target = Type;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl FromMeta for RedbType {
fn from_meta(item: &syn::Meta) -> darling::Result<Self> {
let mut ty = Type::from_meta(item)?;
if let Type::Reference(ref mut ref_ty) = ty {
ref_ty.lifetime = Some(Lifetime {
apostrophe: ref_ty.span(),
ident: format_ident!("static"),
})
}
Ok(RedbType(ty))
}
}