alt
This commit is contained in:
+9
-25
@@ -335,32 +335,16 @@ fn parse_impl(item_impl: &ItemImpl) -> Option<RustDecl> {
|
||||
/// Handles both `///` comments (converted to `#[doc = "..."]` by syn)
|
||||
/// and explicit `#[doc = "..."]` attributes.
|
||||
fn extract_docstring(attrs: &[Attribute]) -> Option<String> {
|
||||
let mut docs = Vec::new();
|
||||
// Convert the attribute’s token stream back to source‑like text.
|
||||
let text = attrs
|
||||
.iter()
|
||||
.map(|a| a.tokens.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
for attr in attrs {
|
||||
// `path()` is the correct method; `path` is a field
|
||||
if attr.path().is_ident("doc") {
|
||||
// #[doc = "…"]
|
||||
if let Ok(meta) = attr.parse_meta() {
|
||||
if let syn::Meta::NameValue(nv) = meta {
|
||||
// The value is an `Expr`. Pull out a string literal.
|
||||
if let syn::Expr::Lit(syn::ExprLit {
|
||||
lit: syn::Lit::Str(lit_str),
|
||||
..
|
||||
}) = nv.value
|
||||
{
|
||||
docs.push(lit_str.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if docs.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(docs.join("\n"))
|
||||
}
|
||||
let re = Regex::new(r#"(?m)^\s*(?:///|#\[\s*doc\s*=\s*")(.+?)(?:")?$"#).ok()?;
|
||||
re.captures(&text)
|
||||
.and_then(|c| c.get(1).map(|m| m.as_str().to_string()))
|
||||
}
|
||||
|
||||
fn parse_mod(item_mod: &ItemMod) -> Option<RustDecl> {
|
||||
|
||||
Reference in New Issue
Block a user