async-trait icon indicating copy to clipboard operation
async-trait copied to clipboard

cargo doc generates ugly documentation

Open nullchinchilla opened this issue 3 years ago • 2 comments

cargo doc seems to generate documentation for the trait based on the expanded code, rather than the pre-expansion code. e.g.

image

Is this fundamentally unfixable, or is there some way of getting cargo doc to display the trait with the pre-expansion form, document the methods as async fn etc?

nullchinchilla avatar Aug 17 '22 04:08 nullchinchilla

This would need to be a feature request for rustdoc to support emitting async fn in traits. Currently there is no way.

dtolnay avatar Aug 17 '22 05:08 dtolnay

That is very unfortunate. Is the only way manually documenting the async fns then?

nullchinchilla avatar Aug 17 '22 19:08 nullchinchilla

Any known workarounds for this one?

WhyNotHugo avatar May 22 '23 11:05 WhyNotHugo

Yeah you can do:

# Cargo.toml

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docs_rs"]
// lib.rs

#![cfg_attr(docs_rs, feature(async_fn_in_trait))]

#[cfg_attr(not(docs_rs), async_trait::async_trait)]
pub trait Trait {
    async fn f();
}

dtolnay avatar May 23 '23 15:05 dtolnay