use crate::parser::Parser;
use syn::{Attribute, DeriveInput, Expr, Generics, Ident, Type, Visibility};
#[derive(Clone, Debug)]
pub struct ServiceData {
pub metadata: MetaData,
pub properties: Vec<Property>,
}
impl ServiceData {
pub fn from_derive_input(input: &DeriveInput) -> syn::Result<Self> {
Ok(ServiceData {
metadata: input.parse_as()?,
properties: input.parse_as()?,
})
}
}
#[derive(Clone, Debug)]
pub struct MetaData {
pub identifier: Ident,
pub interface: Type,
pub generics: Generics,
pub visibility: Visibility,
}
#[derive(Copy, Clone, Debug)]
pub enum PropertyType {
Parameter,
Component,
Provided,
}
#[derive(Clone, Debug)]
pub struct Property {
pub property_name: Ident,
pub ty: Type,
pub property_type: PropertyType,
pub default: PropertyDefault,
pub doc_comment: Vec<Attribute>,
}
impl Property {
pub fn is_service(&self) -> bool {
match self.property_type {
PropertyType::Component | PropertyType::Provided => true,
PropertyType::Parameter => false,
}
}
}
#[derive(Clone, Debug)]
pub enum PropertyDefault {
Provided(Box<Expr>),
NotProvided,
NoDefault,
}