| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.106 crate/::{Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, Spanrust-analyzer cargo proc-macro2 1.0.106 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#}; |
| 4 | use quoterust-analyzer cargo quote 1.0.44 crate/::{ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#, quoterust-analyzer cargo quote 1.0.44 quote!, quote_spannedrust-analyzer cargo quote 1.0.44 quote_spanned!}; |
| 5 | use synrust-analyzer cargo syn 2.0.117 crate/::{ |
| 6 | Tokenrust-analyzer cargo syn 2.0.117 token/Token!, Variantrust-analyzer cargo syn 2.0.117 data/Variant#, metarust-analyzer cargo syn 2.0.117 meta/::ParseNestedMetarust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#, parserust-analyzer cargo syn 2.0.117 parse/::Parserust-analyzer cargo syn 2.0.117 parse/Parse#, punctuatedrust-analyzer cargo syn 2.0.117 punctuated/::Punctuatedrust-analyzer cargo syn 2.0.117 punctuated/Punctuated#, spannedrust-analyzer cargo syn 2.0.117 spanned/::Spannedrust-analyzer cargo syn 2.0.117 spanned/Spanned#, |
| 7 | tokenrust-analyzer cargo syn 2.0.117 token/::Commarust-analyzer cargo syn 2.0.117 token/Comma#, |
| 8 | }; |
| 9 | |
| 10 | pub trait ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem# { |
| 11 | fn get_namerust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_name().(&self) -> &'static str; |
| 12 | fn get_foundrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_found().(&self) -> bool; |
| 13 | fn get_requiredrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_required().(&self) -> bool; |
| 14 | fn parse_nestedrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#parse_nested().(&mut self, meta: &ParseNestedMetarust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()>>; |
| 15 | } |
| 16 | |
| 17 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 18 | pub struct NestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#<T> { |
| 19 | pub namerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#name.: &'static str, |
| 20 | pub value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value_required.: bool, |
| 21 | pub foundrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#found.: bool, |
| 22 | pub requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#required.: bool, |
| 23 | pub valuerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, |
| 24 | } |
| 25 | |
| 26 | impl<T: Parserust-analyzer cargo syn 2.0.117 parse/Parse# + ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for NestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#<T> { |
| 27 | fn fmtrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 28 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("NestedMetaItem") |
| 29 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("name", &self.namerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#name.) |
| 30 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("required", &self.requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#required.) |
| 31 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("value_required", &self.value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value_required.) |
| 32 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("found", &self.foundrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#found.) |
| 33 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("value", &self.valuerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| quoterust-analyzer cargo quote 1.0.44 quote!!(#v))) |
| 34 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl<T: Parserust-analyzer cargo syn 2.0.117 parse/Parse#> NestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#<T> { |
| 39 | pub const fn newrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]new().(name: &'static str) -> Selfrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`] { |
| 40 | Selfrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`] { |
| 41 | requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#required.: false, |
| 42 | namerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#name., |
| 43 | foundrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#found.: false, |
| 44 | value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value_required.: false, |
| 45 | valuerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 46 | } |
| 47 | } |
| 48 | pub fn requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]required().(mut self) -> Selfrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`] { |
| 49 | self.requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#required. = true; |
| 50 | self |
| 51 | } |
| 52 | // Note: this flags the `value` as required, that is, |
| 53 | // the parameter after the equal: `name = value`. |
| 54 | pub const fn value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]value_required().(mut self) -> Selfrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`] { |
| 55 | self.value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value_required. = true; |
| 56 | self |
| 57 | } |
| 58 | pub const fn value_optionalrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]value_optional().(mut self) -> Selfrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`] { |
| 59 | self.value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value_required. = false; |
| 60 | self |
| 61 | } |
| 62 | fn parse_nested_forcedrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]parse_nested_forced().(&mut self, meta: &ParseNestedMetarust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()> { |
| 63 | if self.value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value_required. || meta.inputrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#input..peekrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]peek().(Tokenrust-analyzer cargo syn 2.0.117 token/Token!![=]) { |
| 64 | let _eq: Tokenrust-analyzer cargo syn 2.0.117 token/Token!![=] = meta.inputrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#input..parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 65 | self.valuerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta.inputrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#input..parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 66 | } |
| 67 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 68 | } |
| 69 | } |
| 70 | impl<T: Parserust-analyzer cargo syn 2.0.117 parse/Parse#> ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem# for NestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#<T> { |
| 71 | fn get_namerust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][ParseNestedMetaItem]get_name().(&self) -> &'static str { |
| 72 | self.namerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#name. |
| 73 | } |
| 74 | fn parse_nestedrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][ParseNestedMetaItem]parse_nested().(&mut self, meta: &ParseNestedMetarust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()>> { |
| 75 | if meta.pathrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().(self.namerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#name.) { |
| 76 | self.foundrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#found. = true; |
| 77 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.parse_nested_forcedrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]parse_nested_forced().(meta)) |
| 78 | } else { |
| 79 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 80 | } |
| 81 | } |
| 82 | fn get_foundrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][ParseNestedMetaItem]get_found().(&self) -> bool { |
| 83 | self.foundrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#found. |
| 84 | } |
| 85 | fn get_requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][ParseNestedMetaItem]get_required().(&self) -> bool { |
| 86 | self.requiredrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#required. |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | pub fn check_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/check_meta_items().(span: Spanrust-analyzer cargo proc-macro2 1.0.106 Span#, items: &mut [&mut dyn ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#]) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()> { |
| 91 | let mut err: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 92 | for item in &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().items { |
| 93 | if item.get_requiredrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_required().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().item.get_foundrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_found().() { |
| 94 | let nerr = synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::newrust-analyzer cargo syn 2.0.117 error/impl#[Error]new().( |
| 95 | span, |
| 96 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("attribute `{}` must be specified", item.get_namerust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_name().()), |
| 97 | ); |
| 98 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut err) = err { |
| 99 | err.combinerust-analyzer cargo syn 2.0.117 error/impl#[Error]combine().(nerr); |
| 100 | } else { |
| 101 | err = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(nerr); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | match err { |
| 106 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), |
| 107 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 108 | } |
| 109 | } |
| 110 | fn parse_nested_meta_items_from_fnrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items_from_fn().( |
| 111 | parse_nested_meta: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#( |
| 112 | &mut dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(ParseNestedMetarust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()>, |
| 113 | ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()>, |
| 114 | items: &mut [&mut dyn ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#], |
| 115 | ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()> { |
| 116 | parse_nested_meta(&mut |meta| { |
| 117 | for item in &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().items { |
| 118 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(res) = item.parse_nestedrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#parse_nested().(&meta) { |
| 119 | return res; |
| 120 | } |
| 121 | } |
| 122 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.117 meta/impl#[`ParseNestedMeta<'a>`]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 123 | "unknown attribute `{}`. Possible attributes are {}", |
| 124 | meta.pathrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#path..get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 125 | items |
| 126 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 127 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("`{}`", i.get_namerust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#get_name().())) |
| 128 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 129 | .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(", ") |
| 130 | ))) |
| 131 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 132 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 133 | } |
| 134 | |
| 135 | pub fn parse_nested_meta_items_from_streamrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items_from_stream().( |
| 136 | input: TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#, |
| 137 | items: &mut [&mut dyn ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#], |
| 138 | ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<()> { |
| 139 | parse_nested_meta_items_from_fnrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items_from_fn().( |
| 140 | |f| { |
| 141 | let p = synrust-analyzer cargo syn 2.0.117 crate/::metarust-analyzer cargo syn 2.0.117 meta/::parserrust-analyzer cargo syn 2.0.117 meta/parser().(f); |
| 142 | synrust-analyzer cargo syn 2.0.117 crate/::parserust-analyzer cargo syn 2.0.117 parse/::Parserrust-analyzer cargo syn 2.0.117 parse/Parser#::parserust-analyzer cargo syn 2.0.117 parse/Parser#parse().(p, input.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 143 | }, |
| 144 | items, |
| 145 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 146 | check_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/check_meta_items().(Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().(), items) |
| 147 | } |
| 148 | |
| 149 | pub fn parse_nested_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items().<'a>( |
| 150 | attrs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a synrust-analyzer cargo syn 2.0.117 crate/::Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#>, |
| 151 | attr_name: &str, |
| 152 | items: &mut [&mut dyn ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#], |
| 153 | ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a synrust-analyzer cargo syn 2.0.117 crate/::Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#>> { |
| 154 | let attr = attrs |
| 155 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().() |
| 156 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|attr| attr.pathrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().(attr_name)); |
| 157 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr) = attr { |
| 158 | parse_nested_meta_items_from_fnrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items_from_fn().(|x| attr.parse_nested_metarust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]parse_nested_meta().(x), items)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 159 | check_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/check_meta_items().(attr.spanrust-analyzer cargo syn 2.0.117 spanned/impl#[T][Spanned]span().(), items)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 160 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr)) |
| 161 | } else { |
| 162 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | pub fn parse_optional_nested_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/parse_optional_nested_meta_items().<'a>( |
| 167 | attrs: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a synrust-analyzer cargo syn 2.0.117 crate/::Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#>, |
| 168 | attr_name: &str, |
| 169 | items: &mut [&mut dyn ParseNestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/ParseNestedMetaItem#], |
| 170 | ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a synrust-analyzer cargo syn 2.0.117 crate/::Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#>> { |
| 171 | let attr = attrs |
| 172 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().() |
| 173 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|attr| attr.pathrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().(attr_name)); |
| 174 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr) = attr { |
| 175 | if let synrust-analyzer cargo syn 2.0.117 crate/::Metarust-analyzer cargo syn 2.0.117 attr/Meta#::Pathrust-analyzer cargo syn 2.0.117 attr/Meta#Path#(_) = attr.metarust-analyzer cargo syn 2.0.117 attr/Attribute#meta. { |
| 176 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr)) |
| 177 | } else { |
| 178 | parse_nested_meta_items_from_fnrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items_from_fn().(|x| attr.parse_nested_metarust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]parse_nested_meta().(x), items)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 179 | check_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/check_meta_items().(attr.spanrust-analyzer cargo syn 2.0.117 spanned/impl#[T][Spanned]span().(), items)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 180 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr)) |
| 181 | } |
| 182 | } else { |
| 183 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | #[cfg(feature = "proc_macro_crate")] |
| 188 | pub fn crate_ident_newrust-analyzer cargo glib-macros 0.22.6 utils/crate_ident_new().() -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 189 | use proc_macro_craterust-analyzer cargo proc-macro-crate 3.4.0 crate/::{FoundCraterust-analyzer cargo proc-macro-crate 3.4.0 FoundCrate#, crate_namerust-analyzer cargo proc-macro-crate 3.4.0 crate_name().}; |
| 190 | |
| 191 | match crate_namerust-analyzer cargo proc-macro-crate 3.4.0 crate_name().("glib") { |
| 192 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(FoundCraterust-analyzer cargo proc-macro-crate 3.4.0 FoundCrate#::Namerust-analyzer cargo proc-macro-crate 3.4.0 FoundCrate#Name#(name)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name), |
| 193 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(FoundCraterust-analyzer cargo proc-macro-crate 3.4.0 FoundCrate#::Itselfrust-analyzer cargo proc-macro-crate 3.4.0 FoundCrate#Itself#) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("glib".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 194 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 195 | } |
| 196 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| { |
| 197 | let glib = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().(&s, Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 198 | quoterust-analyzer cargo quote 1.0.44 quote!!(#glib) |
| 199 | }) |
| 200 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| { |
| 201 | // We couldn't find the glib crate (renamed or not) so let's just hope it's in scope! |
| 202 | // |
| 203 | // We will be able to have this information once this code is stable: |
| 204 | // |
| 205 | // ``` |
| 206 | // let span = Span::call_site(); |
| 207 | // let source = span.source_file(); |
| 208 | // let file_path = source.path(); |
| 209 | // ``` |
| 210 | // |
| 211 | // Then we can use proc_macro to parse the file and check if glib is imported somehow. |
| 212 | let glib = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().("glib", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 213 | quoterust-analyzer cargo quote 1.0.44 quote!!(#glib) |
| 214 | }) |
| 215 | } |
| 216 | |
| 217 | #[cfg(not(feature = "proc_macro_crate"))] |
| 218 | pub fn crate_ident_new() -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 219 | let glib = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::new("glib", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_site()); |
| 220 | quoterust-analyzer cargo quote 1.0.44 crate/!(#glib) |
| 221 | } |
| 222 | |
| 223 | // Generate i32 to enum mapping, used to implement |
| 224 | // glib::translate::TryFromGlib<i32>, such as: |
| 225 | // |
| 226 | // if value == Animal::Goat as i32 { |
| 227 | // return Some(Animal::Goat); |
| 228 | // } |
| 229 | pub fn gen_enum_from_glibrust-analyzer cargo glib-macros 0.22.6 utils/gen_enum_from_glib().( |
| 230 | enum_name: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, |
| 231 | enum_variants: &Punctuatedrust-analyzer cargo syn 2.0.117 punctuated/Punctuated#<Variantrust-analyzer cargo syn 2.0.117 data/Variant#, Commarust-analyzer cargo syn 2.0.117 token/Comma#>, |
| 232 | ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 233 | // FIXME: can we express this with a match()? |
| 234 | let recurse = enum_variants.iterrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|v| { |
| 235 | let name = &v.identrust-analyzer cargo syn 2.0.117 data/Variant#ident.; |
| 236 | quote_spannedrust-analyzer cargo quote 1.0.44 quote_spanned!! { v.spanrust-analyzer cargo syn 2.0.117 spanned/impl#[T][Spanned]span().() => |
| 237 | if value == #enum_name::#name as i32 { |
| 238 | return ::core::option::Option::Some(#enum_name::#name); |
| 239 | } |
| 240 | } |
| 241 | }); |
| 242 | quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 243 | #(#recurse)* |
| 244 | ::core::option::Option::None |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // These tests are useful to pinpoint the exact location of a macro panic |
| 249 | // by running `cargo test --lib` |
| 250 | #[cfg(test)] |
| 251 | mod testsrust-analyzer cargo glib-macros 0.22.6 utils/tests/ { |
| 252 | use synrust-analyzer cargo syn 2.0.117 crate/::{DeriveInputrust-analyzer cargo syn 2.0.117 derive/DeriveInput#, parse_quoterust-analyzer cargo syn 2.0.117 parse_quote/}; |
| 253 | |
| 254 | use superrust-analyzer cargo glib-macros 0.22.6 utils/::*; |
| 255 | |
| 256 | fn boxed_stubrust-analyzer cargo glib-macros 0.22.6 utils/tests/boxed_stub().() -> DeriveInputrust-analyzer cargo syn 2.0.117 derive/DeriveInput# { |
| 257 | parse_quoterust-analyzer cargo syn 2.0.117 parse_quote/parse_quote!!( |
| 258 | #[boxed_type(name = "Author")] |
| 259 | struct Author { |
| 260 | name: String, |
| 261 | } |
| 262 | ) |
| 263 | } |
| 264 | |
| 265 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 266 | fn check_attr_foundrust-analyzer cargo glib-macros 0.22.6 utils/tests/check_attr_found().() { |
| 267 | let input = boxed_stubrust-analyzer cargo glib-macros 0.22.6 utils/tests/boxed_stub().(); |
| 268 | let found = parse_nested_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items().(&input.attrsrust-analyzer cargo syn 2.0.117 derive/DeriveInput#attrs., "boxed_type", &mut []); |
| 269 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(found, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_))); |
| 270 | } |
| 271 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 272 | fn required_name_presentrust-analyzer cargo glib-macros 0.22.6 utils/tests/required_name_present().() { |
| 273 | let input = boxed_stubrust-analyzer cargo glib-macros 0.22.6 utils/tests/boxed_stub().(); |
| 274 | let mut gtype_name = NestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#::<synrust-analyzer cargo syn 2.0.117 crate/::LitStrrust-analyzer cargo syn 2.0.117 lit/LitStr#>::newrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]new().("name") |
| 275 | .requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]required().() |
| 276 | .value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]value_required().(); |
| 277 | let _ = parse_nested_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items().(&input.attrsrust-analyzer cargo syn 2.0.117 derive/DeriveInput#attrs., "boxed_type", &mut [&mut gtype_name]); |
| 278 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(gtype_name.get_foundrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][ParseNestedMetaItem]get_found().()); |
| 279 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 280 | gtype_name.valuerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.valuerust-analyzer cargo syn 2.0.117 lit/impl#[LitStr]value().()), |
| 281 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Author".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 282 | ); |
| 283 | } |
| 284 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 285 | fn required_name_nonerust-analyzer cargo glib-macros 0.22.6 utils/tests/required_name_none().() { |
| 286 | let input: DeriveInputrust-analyzer cargo syn 2.0.117 derive/DeriveInput# = parse_quoterust-analyzer cargo syn 2.0.117 parse_quote/parse_quote!!( |
| 287 | #[boxed_type(name)] |
| 288 | struct Author { |
| 289 | name: String, |
| 290 | } |
| 291 | ); |
| 292 | let mut gtype_name = NestedMetaItemrust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#::<synrust-analyzer cargo syn 2.0.117 crate/::LitStrrust-analyzer cargo syn 2.0.117 lit/LitStr#>::newrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]new().("name") |
| 293 | .requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]required().() |
| 294 | .value_requiredrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`]value_required().(); |
| 295 | let found = parse_nested_meta_itemsrust-analyzer cargo glib-macros 0.22.6 utils/parse_nested_meta_items().(&input.attrsrust-analyzer cargo syn 2.0.117 derive/DeriveInput#attrs., "boxed_type", &mut [&mut gtype_name]); |
| 296 | // The argument value was specified as required, so an error is returned |
| 297 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(found.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 298 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(gtype_name.valuerust-analyzer cargo glib-macros 0.22.6 utils/NestedMetaItem#value..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 299 | |
| 300 | // The argument key must be found though |
| 301 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(gtype_name.get_foundrust-analyzer cargo glib-macros 0.22.6 utils/impl#[`NestedMetaItem<T>`][ParseNestedMetaItem]get_found().()); |
| 302 | } |
| 303 | } |