| 1 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.95 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#; |
| 2 | use quoterust-analyzer cargo quote 1.0.40 crate/::quoterust-analyzer cargo quote 1.0.40 quote!; |
| 3 | use synrust-analyzer cargo syn 2.0.104 crate/::Visibilityrust-analyzer cargo syn 2.0.104 restriction/Visibility#; |
| 4 | |
| 5 | use craterust-analyzer cargo bitfields-impl 1.0.0 crate/::generationrust-analyzer cargo bitfields-impl 1.0.0 generation/::commonrust-analyzer cargo bitfields-impl 1.0.0 generation/common/::{ |
| 6 | generate_setting_fields_default_values_tokensrust-analyzer cargo bitfields-impl 1.0.0 generation/common/generate_setting_fields_default_values_tokens()., generate_setting_fields_to_zero_tokensrust-analyzer cargo bitfields-impl 1.0.0 generation/common/generate_setting_fields_to_zero_tokens()., |
| 7 | }; |
| 8 | use craterust-analyzer cargo bitfields-impl 1.0.0 crate/::parsingrust-analyzer cargo bitfields-impl 1.0.0 parsing/::bitfield_fieldrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/::BitfieldFieldrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#; |
| 9 | |
| 10 | /// Generates the `new` function for the bitfield. |
| 11 | /// |
| 12 | /// Output: |
| 13 | /// |
| 14 | /// ```ignore |
| 15 | /// fn new() -> Self { ... } |
| 16 | /// ``` |
| 17 | pub(craterust-analyzer cargo bitfields-impl 1.0.0 crate/) fn generate_new_function_tokensrust-analyzer cargo bitfields-impl 1.0.0 generation/new_impl/generate_new_function_tokens().( |
| 18 | vis: Visibilityrust-analyzer cargo syn 2.0.104 restriction/Visibility#, |
| 19 | fields: &[BitfieldFieldrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#], |
| 20 | ignored_fields: &[BitfieldFieldrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#], |
| 21 | bitfield_type: &synrust-analyzer cargo syn 2.0.104 crate/::Typerust-analyzer cargo syn 2.0.104 ty/Type#, |
| 22 | ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream# { |
| 23 | let setting_fields_default_values_tokens = generate_setting_fields_default_values_tokensrust-analyzer cargo bitfields-impl 1.0.0 generation/common/generate_setting_fields_default_values_tokens().( |
| 24 | bitfield_type, |
| 25 | fields, |
| 26 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 27 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ignored_fields.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 28 | ); |
| 29 | let documentation = "Creates a new bitfield instance."; |
| 30 | |
| 31 | let ignored_fields_defaults = ignored_fields.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|field| { |
| 32 | let field_name = &field.namerust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#name.; |
| 33 | let field_ty = &field.tyrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#ty.; |
| 34 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 35 | #field_name: <#field_ty>::default(), |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | let initialize_struct_tokens = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ignored_fields.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 40 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 41 | Self { |
| 42 | val: 0, |
| 43 | #( #ignored_fields_defaults )* |
| 44 | } |
| 45 | } |
| 46 | } else { |
| 47 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 48 | Self(0) |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | let const_ident_tokens = ignored_fields.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().().thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| quoterust-analyzer cargo quote 1.0.40 quote!! { const }); |
| 53 | |
| 54 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 55 | #[doc = #documentation] |
| 56 | #vis #const_ident_tokens fn new() -> Self { |
| 57 | let mut this = #initialize_struct_tokens; |
| 58 | #setting_fields_default_values_tokens |
| 59 | this |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /// Generates the `new` function for the bitfield without setting default |
| 65 | /// values. |
| 66 | /// |
| 67 | /// Output: |
| 68 | /// |
| 69 | /// ```ignore |
| 70 | /// fn new_without_defaults() -> Self { ... } |
| 71 | /// ``` |
| 72 | pub(craterust-analyzer cargo bitfields-impl 1.0.0 crate/) fn generate_new_without_defaults_function_tokensrust-analyzer cargo bitfields-impl 1.0.0 generation/new_impl/generate_new_without_defaults_function_tokens().( |
| 73 | vis: Visibilityrust-analyzer cargo syn 2.0.104 restriction/Visibility#, |
| 74 | fields: &[BitfieldFieldrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#], |
| 75 | ignored_fields: &[BitfieldFieldrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#], |
| 76 | bitfield_type: &synrust-analyzer cargo syn 2.0.104 crate/::Typerust-analyzer cargo syn 2.0.104 ty/Type#, |
| 77 | ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream# { |
| 78 | let setting_fields_to_zero_tokens = generate_setting_fields_to_zero_tokensrust-analyzer cargo bitfields-impl 1.0.0 generation/common/generate_setting_fields_to_zero_tokens().( |
| 79 | bitfield_type, |
| 80 | fields, |
| 81 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 82 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ignored_fields.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 83 | ); |
| 84 | let documentation = "Creates a new bitfield instance without setting any default values."; |
| 85 | |
| 86 | let ignored_fields_defaults = ignored_fields.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|field| { |
| 87 | let field_name = &field.namerust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#name.; |
| 88 | let field_ty = &field.tyrust-analyzer cargo bitfields-impl 1.0.0 parsing/bitfield_field/BitfieldField#ty.; |
| 89 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 90 | #field_name: <#field_ty>::default(), |
| 91 | } |
| 92 | }); |
| 93 | |
| 94 | let initialize_struct_tokens = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ignored_fields.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 95 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 96 | Self { |
| 97 | val: 0, |
| 98 | #( #ignored_fields_defaults )* |
| 99 | } |
| 100 | } |
| 101 | } else { |
| 102 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 103 | Self(0) |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | let const_ident_tokens = ignored_fields.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().().thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| quoterust-analyzer cargo quote 1.0.40 quote!! { const }); |
| 108 | |
| 109 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 110 | #[doc = #documentation] |
| 111 | #vis #const_ident_tokens fn new_without_defaults() -> Self { |
| 112 | let mut this = #initialize_struct_tokens; |
| 113 | #setting_fields_to_zero_tokens |
| 114 | this |
| 115 | } |
| 116 | } |
| 117 | } |