mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Improved doc
attr extraction
This commit is contained in:
parent
b91c53588d
commit
d1ac816642
1 changed files with 11 additions and 13 deletions
|
@ -53,19 +53,7 @@ impl CommandAttrs {
|
|||
let attributes = attributes.iter().map(|attr| {
|
||||
if attr.path.is_ident("doc") {
|
||||
// Extract the token literal from the doc attribute.
|
||||
let description = attr
|
||||
.tokens
|
||||
.clone()
|
||||
.into_iter()
|
||||
.nth(1)
|
||||
.map(|t| {
|
||||
// remove first and last quotes only, is expected to be a string literal
|
||||
let mut s = t.to_string();
|
||||
s.remove(0);
|
||||
s.pop();
|
||||
s.trim().replace(r"\\n", "\n")
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let description = parse_doc_comment(attr).unwrap_or_default();
|
||||
// Convert the doc attribute into a command description attribute.
|
||||
let sp = attr.span();
|
||||
let attr = Attribute::parse_outer
|
||||
|
@ -152,3 +140,13 @@ fn is_command_attribute(a: &Attribute) -> bool {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_doc_comment(attr: &Attribute) -> Option<String> {
|
||||
#[allow(clippy::collapsible_match)]
|
||||
if let syn::Meta::NameValue(syn::MetaNameValue { lit, .. }) = attr.parse_meta().ok()? {
|
||||
if let syn::Lit::Str(s) = lit {
|
||||
return Some(s.value().trim().replace(r"\n", "\n"));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue