educe/common/
unsafe_punctuated_meta.rs

1use syn::{
2    parse::{Parse, ParseStream},
3    punctuated::Punctuated,
4    Meta, Token,
5};
6
7pub(crate) struct UnsafePunctuatedMeta {
8    pub(crate) list:       Punctuated<Meta, Token![,]>,
9    pub(crate) has_unsafe: bool,
10}
11
12impl Parse for UnsafePunctuatedMeta {
13    #[inline]
14    fn parse(input: ParseStream) -> syn::Result<Self> {
15        let has_unsafe = input.parse::<Token![unsafe]>().is_ok();
16
17        if input.is_empty() {
18            return Ok(Self {
19                list: Punctuated::new(),
20                has_unsafe,
21            });
22        }
23
24        if has_unsafe {
25            input.parse::<Token![,]>()?;
26        }
27
28        let list = input.parse_terminated(Meta::parse, Token![,])?;
29
30        Ok(Self {
31            list,
32            has_unsafe,
33        })
34    }
35}