1use syn::{
2 parse::{Parse, ParseStream},
3 punctuated::Punctuated,
4 Meta, Token, Type,
5};
6
7pub(crate) struct TypeWithPunctuatedMeta {
8 pub(crate) ty: Type,
9 pub(crate) list: Punctuated<Meta, Token![,]>,
10}
11
12impl Parse for TypeWithPunctuatedMeta {
13 #[inline]
14 fn parse(input: ParseStream) -> syn::Result<Self> {
15 let ty = input.parse::<Type>()?;
16
17 if input.is_empty() {
18 return Ok(Self {
19 ty,
20 list: Punctuated::new(),
21 });
22 }
23
24 input.parse::<Token![,]>()?;
25
26 let list = input.parse_terminated(Meta::parse, Token![,])?;
27
28 Ok(Self {
29 ty,
30 list,
31 })
32 }
33}
34
35#[inline]
36pub(crate) fn dereference(ty: &Type) -> &Type {
37 if let Type::Reference(ty) = ty {
38 dereference(ty.elem.as_ref())
39 } else {
40 ty
41 }
42}
43
44#[inline]
45pub(crate) fn dereference_changed(ty: &Type) -> (&Type, bool) {
46 if let Type::Reference(ty) = ty {
47 (dereference(ty.elem.as_ref()), true)
48 } else {
49 (ty, false)
50 }
51}