Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using cargo-readme as a library for custom doc generation #109

Open
nyurik opened this issue Sep 18, 2024 · 0 comments
Open

Using cargo-readme as a library for custom doc generation #109

nyurik opened this issue Sep 18, 2024 · 0 comments

Comments

@nyurik
Copy link

nyurik commented Sep 18, 2024

I am implementing a proc-macro which allows users to generate Varnish caching proxy plugins. It would be good for users to automatically generate plugin documentation based on their code's doc comments, combined with the automatic comments by the proc-macro itself, and save that markdown file into the user's code tree.

Possible API:

// This is my proc-macro handler

use {proc_macro as pm, proc_macro2 as pm2};

#[proc_macro_attribute]
pub fn my_attribute(args: pm::TokenStream, input: pm::TokenStream) -> pm::TokenStream {
    // Parse token stream into some item
    let mut parsed_item_mod: ItemMod = syn::parse2::<ItemMod>(pm2::TokenStream::from(input)).unwrap();

    // modify parsed_item_mod doc attributes as needed

    // use readme's crate to generate some file
    // the item var might need to be wrapped into some syn::FileItem
    // Note that here I can control which code get documented and how
    cargo_readme::generate_md_file(parsed_item_mod, "../GENERATED.md");

    // ... finish additional processing and return generated stream to the compiler
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant