mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-31 16:40:37 +01:00
Simplify some checks
This commit is contained in:
parent
2162fbdf5c
commit
7508d53a9b
1 changed files with 20 additions and 10 deletions
|
@ -6,8 +6,12 @@ use crate::{
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
use syn::Attribute;
|
use syn::{
|
||||||
|
parse::{ParseStream, Peek},
|
||||||
|
Attribute, Token,
|
||||||
|
};
|
||||||
|
|
||||||
/// All attributes that can be used for `derive(BotCommands)`
|
/// All attributes that can be used for `derive(BotCommands)`
|
||||||
pub(crate) struct CommandAttrs {
|
pub(crate) struct CommandAttrs {
|
||||||
|
@ -177,15 +181,21 @@ impl CommandAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_command_attribute(a: &Attribute) -> bool {
|
fn is_command_attribute(a: &Attribute) -> bool {
|
||||||
match a.path.get_ident() {
|
matches!(a.path.get_ident(), Some(ident) if ident == "command")
|
||||||
Some(ident) => ident == "command",
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_doc_comment(a: &Attribute) -> bool {
|
fn is_doc_comment(a: &Attribute) -> bool {
|
||||||
match a.path.get_ident() {
|
matches!(a.path.get_ident(), Some(ident) if ident == "doc" && peek_at_token_stream(a.tokens.clone().into(), Token![=]))
|
||||||
Some(ident) => ident == "doc" && a.tokens.to_string().starts_with("= \""),
|
}
|
||||||
_ => false,
|
|
||||||
}
|
fn peek_at_token_stream(s: TokenStream, p: impl Peek) -> bool {
|
||||||
|
// syn be fr challenge 2023 (impossible)
|
||||||
|
use syn::parse::Parser;
|
||||||
|
(|input: ParseStream<'_>| {
|
||||||
|
let r = input.peek(p);
|
||||||
|
_ = input.step(|_| Ok(((), syn::buffer::Cursor::empty())));
|
||||||
|
Ok(r)
|
||||||
|
})
|
||||||
|
.parse(s)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue