| 1 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.66 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream#; |
| 2 | use quoterust-analyzer cargo quote 1.0.32 crate/::{quoterust-analyzer cargo quote 1.0.32 quote!, ToTokensrust-analyzer cargo quote 1.0.32 to_tokens/ToTokens#}; |
| 3 | use synrust-analyzer cargo syn 2.0.28 crate/::{ |
| 4 | spannedrust-analyzer cargo syn 2.0.28 spanned/::Spannedrust-analyzer cargo syn 2.0.28 spanned/Spanned#, Datarust-analyzer cargo syn 2.0.28 derive/Data#, DataEnumrust-analyzer cargo syn 2.0.28 derive/DataEnum#, DataStructrust-analyzer cargo syn 2.0.28 derive/DataStruct#, DeriveInputrust-analyzer cargo syn 2.0.28 derive/DeriveInput#, Errorrust-analyzer cargo syn 2.0.28 error/Error#, Fieldsrust-analyzer cargo syn 2.0.28 data/Fields#, FieldsNamedrust-analyzer cargo syn 2.0.28 data/FieldsNamed#, LitStrrust-analyzer cargo syn 2.0.28 lit/LitStr#, |
| 5 | }; |
| 6 | |
| 7 | use craterust-analyzer cargo magnus-macros 0.8.0 crate/::utilrust-analyzer cargo magnus-macros 0.8.0 util/; |
| 8 | |
| 9 | pub fn expandrust-analyzer cargo magnus-macros 0.8.0 typed_data/expand().(attrs: TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream#, item: TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream# { |
| 10 | quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 11 | #[derive(magnus::DataTypeFunctions, magnus::TypedData)] |
| 12 | #[magnus(#attrs)] |
| 13 | #item |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | pub fn expand_derive_data_type_functionsrust-analyzer cargo magnus-macros 0.8.0 typed_data/expand_derive_data_type_functions().(input: DeriveInputrust-analyzer cargo syn 2.0.28 derive/DeriveInput#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream# { |
| 18 | let ident = input.identrust-analyzer cargo syn 2.0.28 derive/DeriveInput#ident.; |
| 19 | let generics = input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics.; |
| 20 | quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 21 | impl #generics magnus::DataTypeFunctions for #ident #generics {} |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | pub fn expand_derive_typed_datarust-analyzer cargo magnus-macros 0.8.0 typed_data/expand_derive_typed_data().(input: DeriveInputrust-analyzer cargo syn 2.0.28 derive/DeriveInput#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream#, Errorrust-analyzer cargo syn 2.0.28 error/Error#> { |
| 26 | let attrs = match utilrust-analyzer cargo magnus-macros 0.8.0 util/::get_magnus_attributerust-analyzer cargo magnus-macros 0.8.0 util/get_magnus_attribute().(&input.attrsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#attrs.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 27 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 28 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.28 error/Error#::newrust-analyzer cargo syn 2.0.28 error/impl#[Error]new().(input.spanrust-analyzer cargo syn 2.0.28 spanned/impl#[T][Spanned]span().(), "missing #[magnus] attribute")), |
| 29 | }; |
| 30 | |
| 31 | let mut class = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 32 | let mut name = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 33 | let mut mark = false; |
| 34 | let mut size = false; |
| 35 | let mut compact = false; |
| 36 | let mut free_immediately = false; |
| 37 | let mut wb_protected = false; |
| 38 | let mut frozen_shareable = false; |
| 39 | let mut unsafe_generics = false; |
| 40 | |
| 41 | attrs.parse_nested_metarust-analyzer cargo syn 2.0.28 attr/impl#[Attribute]parse_nested_meta().(|meta| { |
| 42 | if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("class") { |
| 43 | class = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta.valuerust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]value().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..parserust-analyzer cargo syn 2.0.28 parse/impl#[`ParseBuffer<'a>`]parse().::<LitStrrust-analyzer cargo syn 2.0.28 lit/LitStr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..valuerust-analyzer cargo syn 2.0.28 lit/impl#[LitStr]value().()); |
| 44 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 45 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("name") { |
| 46 | name = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta.valuerust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]value().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..parserust-analyzer cargo syn 2.0.28 parse/impl#[`ParseBuffer<'a>`]parse().::<LitStrrust-analyzer cargo syn 2.0.28 lit/LitStr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..valuerust-analyzer cargo syn 2.0.28 lit/impl#[LitStr]value().()); |
| 47 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 48 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("mark") { |
| 49 | mark = true; |
| 50 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 51 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("size") { |
| 52 | size = true; |
| 53 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 54 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("compact") { |
| 55 | compact = true; |
| 56 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 57 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("free_immediately") { |
| 58 | free_immediately = true; |
| 59 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 60 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("wb_protected") { |
| 61 | wb_protected = true; |
| 62 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 63 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("frozen_shareable") { |
| 64 | frozen_shareable = true; |
| 65 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 66 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("unsafe_generics") { |
| 67 | unsafe_generics = true; |
| 68 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 69 | } else if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("free_immediatly") { |
| 70 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]error().("unsupported attribute (use free_immediately)")) |
| 71 | } else { |
| 72 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]error().("unsupported attribute")) |
| 73 | } |
| 74 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 75 | |
| 76 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics..to_token_streamrust-analyzer cargo quote 1.0.32 to_tokens/ToTokens#to_token_stream().().is_emptyrust-analyzer cargo proc-macro2 1.0.66 impl#[TokenStream]is_empty().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().unsafe_generics { |
| 77 | let case = if input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics..type_paramsrust-analyzer cargo syn 2.0.28 generics/impl#[Generics]type_params().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 78 | "containing generic types" |
| 79 | } else if input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics..lifetimesrust-analyzer cargo syn 2.0.28 generics/impl#[Generics]lifetimes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 80 | "with lifetimes" |
| 81 | } else if input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics..const_paramsrust-analyzer cargo syn 2.0.28 generics/impl#[Generics]const_params().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 82 | "with const generics" |
| 83 | } else { |
| 84 | "containing generic types" |
| 85 | }; |
| 86 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.28 error/Error#::new_spannedrust-analyzer cargo syn 2.0.28 error/impl#[Error]new_spanned().( |
| 87 | input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics., |
| 88 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("deriving TypedData is not guaranteed to be correct for types {}, consider removing them, or use `#[magnus(unsafe_generics)]` to override this error.", case), |
| 89 | )); |
| 90 | } |
| 91 | |
| 92 | let class = match class { |
| 93 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 94 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.28 error/Error#::newrust-analyzer cargo syn 2.0.28 error/impl#[Error]new().(attrs.spanrust-analyzer cargo syn 2.0.28 spanned/impl#[T][Spanned]span().(), "missing attribute: `class = ...`")), |
| 95 | }; |
| 96 | let name = name.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| class.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()); |
| 97 | |
| 98 | let ident = &input.identrust-analyzer cargo syn 2.0.28 derive/DeriveInput#ident.; |
| 99 | let generics = &input.genericsrust-analyzer cargo syn 2.0.28 derive/DeriveInput#generics.; |
| 100 | |
| 101 | let mut arms = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 102 | if let Datarust-analyzer cargo syn 2.0.28 derive/Data#::Enumrust-analyzer cargo syn 2.0.28 derive/Data#Enum#(DataEnumrust-analyzer cargo syn 2.0.28 derive/DataEnum# { ref variantsrust-analyzer cargo syn 2.0.28 derive/DataEnum#variants., .. }) = input.datarust-analyzer cargo syn 2.0.28 derive/DeriveInput#data. { |
| 103 | for variant in variants.into_iterrust-analyzer cargo syn 2.0.28 punctuated/impl#[`&'a Punctuated<T, P>`][IntoIterator]into_iter().() { |
| 104 | let attrs = match utilrust-analyzer cargo magnus-macros 0.8.0 util/::get_magnus_attributerust-analyzer cargo magnus-macros 0.8.0 util/get_magnus_attribute().(&variant.attrsrust-analyzer cargo syn 2.0.28 data/Variant#attrs.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 105 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 106 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => continue, |
| 107 | }; |
| 108 | let mut class = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 109 | attrs.parse_nested_metarust-analyzer cargo syn 2.0.28 attr/impl#[Attribute]parse_nested_meta().(|meta| { |
| 110 | if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("class") { |
| 111 | class = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta.valuerust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]value().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..parserust-analyzer cargo syn 2.0.28 parse/impl#[`ParseBuffer<'a>`]parse().::<LitStrrust-analyzer cargo syn 2.0.28 lit/LitStr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..valuerust-analyzer cargo syn 2.0.28 lit/impl#[LitStr]value().()); |
| 112 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 113 | } else { |
| 114 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]error().("unsupported attribute")) |
| 115 | } |
| 116 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 117 | let class = match class { |
| 118 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 119 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.28 error/Error#::newrust-analyzer cargo syn 2.0.28 error/impl#[Error]new().(attrs.spanrust-analyzer cargo syn 2.0.28 spanned/impl#[T][Spanned]span().(), "missing attribute: `class = ...`")), |
| 120 | }; |
| 121 | let ident = &variant.identrust-analyzer cargo syn 2.0.28 data/Variant#ident.; |
| 122 | let fetch_class = quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 123 | static CLASS: Lazy<RClass> = Lazy::new(|ruby| { |
| 124 | let class: RClass = ruby.class_object().funcall("const_get", (#class,)).unwrap(); |
| 125 | class.undef_default_alloc_func(); |
| 126 | class |
| 127 | }); |
| 128 | ruby.get_inner(&CLASS) |
| 129 | }; |
| 130 | arms.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(match variant.fieldsrust-analyzer cargo syn 2.0.28 data/Variant#fields. { |
| 131 | Fieldsrust-analyzer cargo syn 2.0.28 data/Fields#::Namedrust-analyzer cargo syn 2.0.28 data/Fields#Named#(_) => quoterust-analyzer cargo quote 1.0.32 quote!! { Self::#ident { .. } => { #fetch_class } }, |
| 132 | Fieldsrust-analyzer cargo syn 2.0.28 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.28 data/Fields#Unnamed#(_) => quoterust-analyzer cargo quote 1.0.32 quote!! { Self::#ident(_) => { #fetch_class } }, |
| 133 | Fieldsrust-analyzer cargo syn 2.0.28 data/Fields#::Unitrust-analyzer cargo syn 2.0.28 data/Fields#Unit# => quoterust-analyzer cargo quote 1.0.32 quote!! { Self::#ident => #fetch_class }, |
| 134 | }); |
| 135 | } |
| 136 | } |
| 137 | let class_for = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().arms.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 138 | quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 139 | fn class_for(ruby: &magnus::Ruby, value: &Self) -> magnus::RClass { |
| 140 | use magnus::{class, Module, Class, RClass, value::{Lazy, ReprValue}}; |
| 141 | #[allow(unreachable_patterns)] |
| 142 | match value { |
| 143 | #(#arms,)* |
| 144 | _ => Self::class(ruby), |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } else { |
| 149 | quoterust-analyzer cargo quote 1.0.32 quote!! {} |
| 150 | }; |
| 151 | |
| 152 | let mut accessors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 153 | if let Datarust-analyzer cargo syn 2.0.28 derive/Data#::Structrust-analyzer cargo syn 2.0.28 derive/Data#Struct#(DataStructrust-analyzer cargo syn 2.0.28 derive/DataStruct# { |
| 154 | fieldsrust-analyzer cargo syn 2.0.28 derive/DataStruct#fields.: Fieldsrust-analyzer cargo syn 2.0.28 data/Fields#::Namedrust-analyzer cargo syn 2.0.28 data/Fields#Named#(FieldsNamedrust-analyzer cargo syn 2.0.28 data/FieldsNamed# { ref namedrust-analyzer cargo syn 2.0.28 data/FieldsNamed#named., .. }), |
| 155 | .. |
| 156 | }) = input.datarust-analyzer cargo syn 2.0.28 derive/DeriveInput#data. |
| 157 | { |
| 158 | for field in named { |
| 159 | let attrs = match utilrust-analyzer cargo magnus-macros 0.8.0 util/::get_magnus_attributerust-analyzer cargo magnus-macros 0.8.0 util/get_magnus_attribute().(&field.attrsrust-analyzer cargo syn 2.0.28 data/Field#attrs.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 160 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => v, |
| 161 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => continue, |
| 162 | }; |
| 163 | let mut read = false; |
| 164 | attrs.parse_nested_metarust-analyzer cargo syn 2.0.28 attr/impl#[Attribute]parse_nested_meta().(|meta| { |
| 165 | if meta.pathrust-analyzer cargo syn 2.0.28 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.28 path/impl#[Path]is_ident().("opaque_attr_reader") { |
| 166 | read = true; |
| 167 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 168 | } else { |
| 169 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.28 meta/impl#[`ParseNestedMeta<'a>`]error().("unsupported attribute")) |
| 170 | } |
| 171 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 172 | let ident = field.identrust-analyzer cargo syn 2.0.28 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 173 | let ty = &field.tyrust-analyzer cargo syn 2.0.28 data/Field#ty.; |
| 174 | if read { |
| 175 | accessors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 176 | #[inline] |
| 177 | fn #ident(&self) -> <#ty as magnus::value::OpaqueVal>::Val { |
| 178 | let handle = magnus::Ruby::get().unwrap(); |
| 179 | handle.get_inner(self.#ident) |
| 180 | } |
| 181 | }); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | let accessor_impl = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().accessors.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 187 | quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 188 | impl #ident { |
| 189 | #(#accessors)* |
| 190 | } |
| 191 | } |
| 192 | } else { |
| 193 | quoterust-analyzer cargo quote 1.0.32 quote!! {} |
| 194 | }; |
| 195 | |
| 196 | let mut builder = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 197 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { magnus::data_type_builder!(#ident, #name) }); |
| 198 | if mark { |
| 199 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .mark() }); |
| 200 | } |
| 201 | if size { |
| 202 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .size() }); |
| 203 | } |
| 204 | if compact { |
| 205 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .compact() }); |
| 206 | } |
| 207 | if free_immediately { |
| 208 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .free_immediately() }); |
| 209 | } |
| 210 | if wb_protected { |
| 211 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .wb_protected() }); |
| 212 | } |
| 213 | if frozen_shareable { |
| 214 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .frozen_shareable() }); |
| 215 | } |
| 216 | builder.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(quoterust-analyzer cargo quote 1.0.32 quote!! { .build() }); |
| 217 | let builder = builder.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<TokenStreamrust-analyzer cargo proc-macro2 1.0.66 TokenStream#>(); |
| 218 | let tokens = quoterust-analyzer cargo quote 1.0.32 quote!! { |
| 219 | #accessor_impl |
| 220 | |
| 221 | unsafe impl #generics magnus::TypedData for #ident #generics { |
| 222 | fn class(ruby: &magnus::Ruby) -> magnus::RClass { |
| 223 | use magnus::{class, Module, Class, RClass, value::{Lazy, ReprValue}}; |
| 224 | static CLASS: Lazy<RClass> = Lazy::new(|ruby| { |
| 225 | let class: RClass = ruby.class_object().funcall("const_get", (#class,)).unwrap(); |
| 226 | class.undef_default_alloc_func(); |
| 227 | class |
| 228 | }); |
| 229 | ruby.get_inner(&CLASS) |
| 230 | } |
| 231 | |
| 232 | fn data_type() -> &'static magnus::DataType { |
| 233 | static DATA_TYPE: magnus::DataType = #builder; |
| 234 | &DATA_TYPE |
| 235 | } |
| 236 | |
| 237 | #class_for |
| 238 | } |
| 239 | }; |
| 240 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tokens) |
| 241 | } |