mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-18 15:20:15 +01:00
Remove unnecessary collect
This commit is contained in:
parent
9a2e39ea01
commit
99685f3dcc
1 changed files with 27 additions and 31 deletions
|
@ -50,39 +50,35 @@ impl CommandAttrs {
|
||||||
pub fn from_attributes(attributes: &[Attribute]) -> Result<Self> {
|
pub fn from_attributes(attributes: &[Attribute]) -> Result<Self> {
|
||||||
use CommandAttrKind::*;
|
use CommandAttrKind::*;
|
||||||
// Convert the `doc` attribute into `command(description = "...")`
|
// Convert the `doc` attribute into `command(description = "...")`
|
||||||
let attributes = attributes
|
let attributes = attributes.iter().map(|attr| {
|
||||||
.iter()
|
if attr.path.is_ident("doc") {
|
||||||
.map(|attr| {
|
// Extract the token literal from the doc attribute.
|
||||||
if attr.path.is_ident("doc") {
|
let description = attr
|
||||||
// Extract the token literal from the doc attribute.
|
.tokens
|
||||||
let description = attr
|
.clone()
|
||||||
.tokens
|
.into_iter()
|
||||||
.clone()
|
.nth(1)
|
||||||
.into_iter()
|
.map(|t| {
|
||||||
.nth(1)
|
// remove first and last quotes only, is expected to be a string literal
|
||||||
.map(|t| {
|
let mut s = t.to_string();
|
||||||
// remove first and last quotes only, is expected to be a string literal
|
s.remove(0);
|
||||||
let mut s = t.to_string();
|
s.pop();
|
||||||
s.remove(0);
|
s.trim().replace(r"\\n", "\n")
|
||||||
s.pop();
|
})
|
||||||
s.trim().replace(r"\\n", "\n")
|
.unwrap_or_default();
|
||||||
})
|
// Convert the doc attribute into a command description attribute.
|
||||||
.unwrap_or_default();
|
let sp = attr.span();
|
||||||
// Convert the doc attribute into a command description attribute.
|
let attr = Attribute::parse_outer
|
||||||
let sp = attr.span();
|
.parse2(quote_spanned!(sp => #[command(description = #description)]))
|
||||||
let attr = Attribute::parse_outer
|
.unwrap();
|
||||||
.parse2(quote_spanned!(sp => #[command(description = #description)]))
|
attr.into_iter().next().unwrap()
|
||||||
.unwrap();
|
} else {
|
||||||
// SAFETY: `parse_outer` always returns a single attribute.
|
attr.clone()
|
||||||
attr.into_iter().next().unwrap()
|
}
|
||||||
} else {
|
});
|
||||||
attr.clone()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
fold_attrs(
|
fold_attrs(
|
||||||
attributes.iter(),
|
attributes,
|
||||||
is_command_attribute,
|
is_command_attribute,
|
||||||
CommandAttr::parse,
|
CommandAttr::parse,
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Reference in a new issue