pub fn parse(
        crate_name: &str,
        attr_params: TokenStream,
        item: TokenStream,
    ) -> ParseResult<ComClass>
    {
        // Parse the inputs.
        let item: ::syn::ItemStruct = ::syn::parse2(item)
            .map_err(|_| ParseError::ComClass("<Unknown>".into(), "Item syntax error".into()))?;

        let attr: ComClassAttr = ::syn::parse2(attr_params).map_err(|e| {
            ParseError::ComClass(
                item.ident.to_string(),
                format!("Attribute syntax error: {}", e),
            )
        })?;

        // First attribute parameter is the CLSID. Parse it.
        let clsid_attr = attr
            .clsid()
            .map_err(|msg| ParseError::ComClass(item.ident.to_string(), msg))?;
        let clsid = match clsid_attr {
            None => Some(crate::utils::generate_clsid(
                crate_name,
                &item.ident.to_string(),
            )),
            Some(StrOption::Str(clsid)) => Some(GUID::parse(&clsid.value()).map_err(|_| {
                ParseError::ComClass(item.ident.to_string(), "Bad CLSID format".into())
            })?),
            Some(StrOption::None) => None,
        };

        // Remaining parameters are coclasses.
        let name = item.ident.clone();
        let interfaces = attr
            .args()
            .into_iter()
            .map(|itf| match itf.get_ident() {
                Some(ident) if ident == "Self" => parse_quote!(#name),
                _ => itf.clone(),
            })
            .collect();

        Ok(ComClass {
            visibility: item.vis.clone(),
            generics: item.generics,
            name,
            clsid,
            interfaces,
        })
    }
/// Creates ComClass from AST elements.
Creates ComClass from AST elements.
Creates ComClass from AST elements .
pub fn parse(
        crate_name: &str,
        attr_params: TokenStream,
        item: TokenStream,
    ) -> ParseResult<ComClass>
    {
        // Parse the inputs.
        let item: ::syn::ItemStruct = ::syn::parse2(item)
            .map_err(|_| ParseError::ComClass("<Unknown>".into(), "Item syntax error".into()))?;
        let attr: ComClassAttr = ::syn::parse2(attr_params).map_err(|e| {
            ParseError::ComClass(
                item.ident.to_string(),
                format!("Attribute syntax error: {}", e),
            )
        })?;
        // First attribute parameter is the CLSID. Parse it.
        let clsid_attr = attr
            .clsid()
            .map_err(|msg| ParseError::ComClass(item.ident.to_string(), msg))?;
        let clsid = match clsid_attr {
            None => Some(crate::utils::generate_clsid(
                crate_name,
                &item.ident.to_string(),
            )),
            Some(StrOption::Str(clsid)) => Some(GUID::parse(&clsid.value()).map_err(|_| {
                ParseError::ComClass(item.ident.to_string(), "Bad CLSID format".into())
            })?),
            Some(StrOption::None) => None,
        };
        // Remaining parameters are coclasses.
        let name = item.ident.clone();
        let interfaces = attr
            .args()
            .into_iter()
            .map(|itf| match itf.get_ident() {
                Some(ident) if ident == "Self" => parse_quote!(#name),
                _ => itf.clone(),
            })
            .collect();
        Ok(ComClass {
            visibility: item.vis.clone(),
            generics: item.generics,
            name,
            clsid,
            interfaces,
        })
    }
pub fn parse ( crate_name : & str , attr_params : TokenStream , item : TokenStream , ) -> ParseResult < ComClass > { // Parse the inputs. let item : :: syn :: ItemStruct = :: syn :: parse2 ( item ) . map_err ( | _ | ParseError :: ComClass ( " " . into ( ) , " " . into ( ) ) ) ? ; let attr : ComClassAttr = :: syn :: parse2 ( attr_params ) . map_err ( | e | { ParseError :: ComClass ( item . ident . to_string ( ) , format ! ( " " e ) , ) } ) ? ; // First attribute parameter is the CLSID. Parse it. let clsid_attr = attr . clsid ( ) . map_err ( | msg | ParseError :: ComClass ( item . ident . to_string ( ) , msg ) ) ? ; let clsid = match clsid_attr { None => Some ( crate :: utils :: generate_clsid ( crate_name , & item . ident . to_string ( ) , ) ) , Some ( StrOption :: Str ( clsid ) ) => Some ( GUID :: parse ( & clsid . value ( ) ) . map_err ( | _ | { ParseError :: ComClass ( item . ident . to_string ( ) , " " . into ( ) ) } ) ? ) , Some ( StrOption :: None ) => None , } ; // Remaining parameters are coclasses. let name = item . ident . clone ( ) ; let interfaces = attr . args ( ) . into_iter ( ) . map ( | itf | match itf . get_ident ( ) { Some ( ident ) if ident == " " => parse_quote ! ( name ) , _ => itf . clone ( ) , } ) . collect ( ) ; Ok ( ComClass { visibility : item . vis . clone ( ) , generics : item . generics , name , clsid , interfaces , } ) }
Creates ComClass from AST elements.
Creates ComClass from AST elements .
crate_name
&str
attr_params
TokenStream
item
TokenStream
crate_name
&str
attr_params
TokenStream
item
TokenStream