Debian Codegraph @

src/setter.rs

raw symbols SCIP
1 #![allow(clippy::useless_let_if_seq)]
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
3
4 use proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::{Spanrust-analyzer cargo proc-macro2 1.0.107 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#};
5 use quoterust-analyzer cargo quote 1.0.47 crate/::{ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#, TokenStreamExtrust-analyzer cargo quote 1.0.47 ext/TokenStreamExt#};
6
7 use craterust-analyzer cargo derive_builder_core 0.20.2 crate/::{BuilderFieldTyperust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#, BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#, Eachrust-analyzer cargo derive_builder_core 0.20.2 options/Each#};
8
9 /// Setter for the struct fields in the build method, implementing
10 /// `quote::ToTokens`.
11 ///
12 /// # Examples
13 ///
14 /// Will expand to something like the following (depending on settings):
15 ///
16 /// ```rust,ignore
17 /// # extern crate proc_macro2;
18 /// # #[macro_use]
19 /// # extern crate quote;
20 /// # extern crate syn;
21 /// # #[macro_use]
22 /// # extern crate derive_builder_core;
23 /// # use derive_builder_core::{Setter, BuilderPattern};
24 /// # fn main() {
25 /// # let mut setter = default_setter!();
26 /// # setter.pattern = BuilderPattern::Mutable;
27 /// #
28 /// # assert_eq!(quote!(#setter).to_string(), quote!(
29 /// # #[allow(unused_mut)]
30 /// pub fn foo(&mut self, value: Foo) -> &mut Self {
31 /// let mut new = self;
32 /// new.foo = ::derive_builder::export::core::option::Option::Some(value);
33 /// new
34 /// }
35 /// # ).to_string());
36 /// # }
37 /// ```
38 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
39 pub struct Setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#<'a> {
40 /// Path to the root of the derive_builder crate.
41 pub crate_rootrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#crate_root.: &'a synrust-analyzer cargo syn 2.0.119 crate/::Pathrust-analyzer cargo syn 2.0.119 path/Path#,
42 /// Enables code generation for this setter fn.
43 pub setter_enabledrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#setter_enabled.: bool,
44 /// Enables code generation for the `try_` variant of this setter fn.
45 pub try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#try_setter.: bool,
46 /// Visibility of the setter, e.g. `syn::Visibility::Public`.
47 pub visibilityrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#visibility.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, synrust-analyzer cargo syn 2.0.119 crate/::Visibilityrust-analyzer cargo syn 2.0.119 restriction/Visibility#>,
48 /// How the setter method takes and returns `self` (e.g. mutably).
49 pub patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern.: BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#,
50 /// Attributes which will be attached to this setter fn.
51 pub attrsrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#attrs.: &'a [synrust-analyzer cargo syn 2.0.119 crate/::Attributerust-analyzer cargo syn 2.0.119 attr/Attribute#],
52 /// Name of this setter fn.
53 pub identrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#ident.: synrust-analyzer cargo syn 2.0.119 crate/::Identrust-analyzer cargo proc-macro2 1.0.107 Ident#,
54 /// Name of the target field.
55 pub field_identrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_ident.: &'a synrust-analyzer cargo syn 2.0.119 crate/::Identrust-analyzer cargo proc-macro2 1.0.107 Ident#,
56 /// Type of the builder field.
57 ///
58 /// The corresonding builder field will be `Option<field_type>`.
59 pub field_typerust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_type.: BuilderFieldTyperust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#<'a>,
60 /// Make the setter generic over `Into<T>`, where `T` is the field type.
61 pub generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into.: bool,
62 /// Make the setter remove the Option wrapper from the setter, remove the need to call Some(...).
63 /// when combined with into, the into is used on the content Type of the Option.
64 pub strip_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#strip_option.: bool,
65 /// Emit extend method.
66 pub eachrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#each.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Eachrust-analyzer cargo derive_builder_core 0.20.2 options/Each#>,
67 }
68
69 impl<'a> ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens# for Setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#<'a> {
70 fn to_tokensrust-analyzer cargo derive_builder_core 0.20.2 setter/impl#[`Setter<'a>`][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#) {
71 if self.setter_enabledrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#setter_enabled. {
72 let crate_root = self.crate_rootrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#crate_root.;
73 let pattern = self.patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern.;
74 let vis = &self.visibilityrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#visibility.;
75 let field_ident = self.field_identrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_ident.;
76 let ident = &self.identrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#ident.;
77 let attrs = self.attrsrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#attrs.;
78
79 let self_param: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
80 let return_ty: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
81 let self_into_return_ty: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
82
83 match pattern {
84 BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Ownedrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Owned# => {
85 self_param = quoterust-analyzer cargo quote 1.0.47 quote!!(self);
86 return_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(Self);
87 self_into_return_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(self);
88 }
89 BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Mutablerust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Mutable# => {
90 self_param = quoterust-analyzer cargo quote 1.0.47 quote!!(&mut self);
91 return_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(&mut Self);
92 self_into_return_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(self);
93 }
94 BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Immutablerust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Immutable# => {
95 self_param = quoterust-analyzer cargo quote 1.0.47 quote!!(&self);
96 return_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(Self);
97 self_into_return_ty =
98 quoterust-analyzer cargo quote 1.0.47 quote!!(#crate_root::export::core::clone::Clone::clone(self));
99 }
100 };
101
102 let ty_params: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
103 let param_ty: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
104 let mut into_value: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
105
106 let (field_type, builder_field_is_option) = self.field_typerust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_type..setter_type_inforust-analyzer cargo derive_builder_core 0.20.2 builder_field/impl#[`BuilderFieldType<'a>`]setter_type_info().();
107
108 let (ty, stripped_option) = {
109 if self.strip_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#strip_option. {
110 match extract_type_from_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_type_from_option().(field_type) {
111 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ty) => (ty, true),
112 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => (field_type, false),
113 }
114 } else {
115 (field_type, false)
116 }
117 };
118
119 if self.generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into. {
120 ty_params = quoterust-analyzer cargo quote 1.0.47 quote!!(<VALUE: #crate_root::export::core::convert::Into<#ty>>);
121 param_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(VALUE);
122 into_value = quoterust-analyzer cargo quote 1.0.47 quote!!(value.into());
123 } else {
124 ty_params = quoterust-analyzer cargo quote 1.0.47 quote!!();
125 param_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(#ty);
126 into_value = quoterust-analyzer cargo quote 1.0.47 quote!!(value);
127 }
128 // If both `stripped_option` and `builder_field_is_option`, the target field is `Option<field_type>`,
129 // the builder field is `Option<Option<field_type>>`, and the setter takes `file_type`, so we must wrap it twice.
130 if stripped_option {
131 into_value = wrap_expression_in_somerust-analyzer cargo derive_builder_core 0.20.2 setter/wrap_expression_in_some().(crate_root, into_value);
132 }
133 if builder_field_is_option {
134 into_value = wrap_expression_in_somerust-analyzer cargo derive_builder_core 0.20.2 setter/wrap_expression_in_some().(crate_root, into_value);
135 }
136
137 tokens.append_allrust-analyzer cargo quote 1.0.47 ext/impl#[TokenStream][TokenStreamExt]append_all().(quoterust-analyzer cargo quote 1.0.47 quote!!(
138 #(#attrs)*
139 #[allow(unused_mut)]
140 #vis fn #ident #ty_params (#self_param, value: #param_ty)
141 -> #return_ty
142 {
143 let mut new = #self_into_return_ty;
144 new.#field_ident = #into_value;
145 new
146 }
147 ));
148
149 if self.try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#try_setter. {
150 let try_ty_params =
151 quoterust-analyzer cargo quote 1.0.47 quote!!(<VALUE: #crate_root::export::core::convert::TryInto<#ty>>);
152 let try_ident = synrust-analyzer cargo syn 2.0.119 crate/::Identrust-analyzer cargo proc-macro2 1.0.107 Ident#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[Ident]new().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("try_{}", ident), Spanrust-analyzer cargo proc-macro2 1.0.107 Span#::call_siterust-analyzer cargo proc-macro2 1.0.107 impl#[Span]call_site().());
153
154 let mut converted = quoterust-analyzer cargo quote 1.0.47 quote!! {converted};
155 if builder_field_is_option {
156 converted = wrap_expression_in_somerust-analyzer cargo derive_builder_core 0.20.2 setter/wrap_expression_in_some().(crate_root, converted);
157 }
158 if stripped_option {
159 converted = wrap_expression_in_somerust-analyzer cargo derive_builder_core 0.20.2 setter/wrap_expression_in_some().(crate_root, converted);
160 }
161
162 tokens.append_allrust-analyzer cargo quote 1.0.47 ext/impl#[TokenStream][TokenStreamExt]append_all().(quoterust-analyzer cargo quote 1.0.47 quote!!(
163 #(#attrs)*
164 #vis fn #try_ident #try_ty_params (#self_param, value: VALUE)
165 -> #crate_root::export::core::result::Result<#return_ty, VALUE::Error>
166 {
167 let converted : #ty = value.try_into()?;
168 let mut new = #self_into_return_ty;
169 new.#field_ident = #converted;
170 Ok(new)
171 }
172 ));
173 }
174
175 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(each) = self.eachrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#each. {
176 let ident_each = &each.namerust-analyzer cargo derive_builder_core 0.20.2 options/Each#name.;
177
178 // Access the collection to extend, initialising with default value if necessary.
179 let get_initialized_collection = if stripped_option {
180 // Outer (builder) Option -> Inner (field) Option -> collection.
181 quoterust-analyzer cargo quote 1.0.47 quote!!(get_or_insert_with(|| Some(
182 #crate_root::export::core::default::Default::default()
183 ))
184 .get_or_insert_with(#crate_root::export::core::default::Default::default))
185 } else {
186 // Outer (builder) Option -> collection.
187 quoterust-analyzer cargo quote 1.0.47 quote!!(get_or_insert_with(
188 #crate_root::export::core::default::Default::default
189 ))
190 };
191
192 let ty_params: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
193 let param_ty: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
194 let into_item: TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#;
195
196 if each.intorust-analyzer cargo derive_builder_core 0.20.2 options/Each#into. {
197 ty_params = quoterust-analyzer cargo quote 1.0.47 quote!!(<VALUE, FROM_VALUE: #crate_root::export::core::convert::Into<VALUE>>);
198 param_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(FROM_VALUE);
199 into_item = quoterust-analyzer cargo quote 1.0.47 quote!!(#crate_root::export::core::convert::Into::into(item));
200 } else {
201 ty_params = quoterust-analyzer cargo quote 1.0.47 quote!!(<VALUE>);
202 param_ty = quoterust-analyzer cargo quote 1.0.47 quote!!(VALUE);
203 into_item = quoterust-analyzer cargo quote 1.0.47 quote!!(item);
204 }
205
206 tokens.append_allrust-analyzer cargo quote 1.0.47 ext/impl#[TokenStream][TokenStreamExt]append_all().(quoterust-analyzer cargo quote 1.0.47 quote!!(
207 #(#attrs)*
208 #[allow(unused_mut)]
209 #vis fn #ident_each #ty_params(#self_param, item: #param_ty) -> #return_ty
210 where
211 #ty: #crate_root::export::core::default::Default + #crate_root::export::core::iter::Extend<VALUE>,
212 {
213 let mut new = #self_into_return_ty;
214 new.#field_ident
215 .#get_initialized_collection
216 .extend(#crate_root::export::core::option::Option::Some(#into_item));
217 new
218 }
219 ));
220 }
221 }
222 }
223 }
224
225 /// Returns expression wrapping `bare_value` in `Some`
226 fn wrap_expression_in_somerust-analyzer cargo derive_builder_core 0.20.2 setter/wrap_expression_in_some().(crate_root: &synrust-analyzer cargo syn 2.0.119 crate/::Pathrust-analyzer cargo syn 2.0.119 path/Path#, bare_value: impl ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream# {
227 quoterust-analyzer cargo quote 1.0.47 quote!!( #crate_root::export::core::option::Option::Some(#bare_value) )
228 }
229
230 // adapted from https://stackoverflow.com/a/55277337/469066
231 // Note that since syn is a parser, it works with tokens.
232 // We cannot know for sure that this is an Option.
233 // The user could, for example, `type MaybeString = std::option::Option<String>`
234 // We cannot handle those arbitrary names.
235 fn extract_type_from_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_type_from_option().(ty: &synrust-analyzer cargo syn 2.0.119 crate/::Typerust-analyzer cargo syn 2.0.119 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&synrust-analyzer cargo syn 2.0.119 crate/::Typerust-analyzer cargo syn 2.0.119 ty/Type#> {
236 use synrust-analyzer cargo syn 2.0.119 crate/::punctuatedrust-analyzer cargo syn 2.0.119 punctuated/::Pairrust-analyzer cargo syn 2.0.119 punctuated/Pair#;
237 use synrust-analyzer cargo syn 2.0.119 crate/::tokenrust-analyzer cargo syn 2.0.119 token/::PathSeprust-analyzer cargo syn 2.0.119 token/PathSep#;
238 use synrust-analyzer cargo syn 2.0.119 crate/::{GenericArgumentrust-analyzer cargo syn 2.0.119 path/GenericArgument#, Pathrust-analyzer cargo syn 2.0.119 path/Path#, PathArgumentsrust-analyzer cargo syn 2.0.119 path/PathArguments#, PathSegmentrust-analyzer cargo syn 2.0.119 path/PathSegment#};
239
240 fn extract_type_pathrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_type_path().(ty: &synrust-analyzer cargo syn 2.0.119 crate/::Typerust-analyzer cargo syn 2.0.119 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Pathrust-analyzer cargo syn 2.0.119 path/Path#> {
241 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty {
242 synrust-analyzer cargo syn 2.0.119 crate/::Typerust-analyzer cargo syn 2.0.119 ty/Type#::Pathrust-analyzer cargo syn 2.0.119 ty/Type#Path#(ref typepath) if typepath.qselfrust-analyzer cargo syn 2.0.119 ty/TypePath#qself..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&typepath.pathrust-analyzer cargo syn 2.0.119 ty/TypePath#path.),
243 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
244 }
245 }
246
247 // TODO store (with lazy static) precomputed parsing of Option when support of rust 1.18 will be removed (incompatible with lazy_static)
248 // TODO maybe optimization, reverse the order of segments
249 fn extract_option_segmentrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_option_segment().(path: &Pathrust-analyzer cargo syn 2.0.119 path/Path#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Pairrust-analyzer cargo syn 2.0.119 punctuated/Pair#<&PathSegmentrust-analyzer cargo syn 2.0.119 path/PathSegment#, &PathSeprust-analyzer cargo syn 2.0.119 token/PathSep#>> {
250 let idents_of_path = path.segmentsrust-analyzer cargo syn 2.0.119 path/Path#segments..iterrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]iter().().foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(), |mut acc, v| {
251 acc.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&v.identrust-analyzer cargo syn 2.0.119 path/PathSegment#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
252 acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('|');
253 acc
254 });
255 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Option|", "std|option|Option|", "core|option|Option|"]
256 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
257 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|s| idents_of_path rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().s)
258 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|_| path.segmentsrust-analyzer cargo syn 2.0.119 path/Path#segments..lastrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]last().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Pairrust-analyzer cargo syn 2.0.119 punctuated/Pair#::Endrust-analyzer cargo syn 2.0.119 punctuated/Pair#End#))
259 }
260
261 extract_type_pathrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_type_path().(ty)
262 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(extract_option_segmentrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_option_segment().)
263 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|pair_path_segment| {
264 let type_params = &pair_path_segment.into_valuerust-analyzer cargo syn 2.0.119 punctuated/impl#[`Pair<T, P>`]into_value().().argumentsrust-analyzer cargo syn 2.0.119 path/PathSegment#arguments.;
265 // It should have only on angle-bracketed param ("<String>"):
266 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().type_params {
267 PathArgumentsrust-analyzer cargo syn 2.0.119 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.119 path/PathArguments#AngleBracketed#(ref params) => params.argsrust-analyzer cargo syn 2.0.119 path/AngleBracketedGenericArguments#args..firstrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]first().(),
268 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
269 }
270 })
271 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|generic_arg| match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().generic_arg {
272 GenericArgumentrust-analyzer cargo syn 2.0.119 path/GenericArgument#::Typerust-analyzer cargo syn 2.0.119 path/GenericArgument#Type#(ref ty) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ty),
273 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
274 })
275 }
276
277 /// Helper macro for unit tests. This is _only_ public in order to be accessible
278 /// from doc-tests too.
279 #[doc(hidden)]
280 #[macro_export]
281 macro_rules! default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter! {
282 () => {
283 Setter {
284 // Deliberately don't use the default value here - make sure
285 // that all test cases are passing crate_root through properly.
286 crate_root: &parse_quote!(::db),
287 setter_enabled: true,
288 try_setter: false,
289 visibility: ::std::borrow::Cow::Owned(parse_quote!(pub)),
290 pattern: BuilderPattern::Mutable,
291 attrs: &vec![],
292 ident: syn::Ident::new("foo", ::proc_macro2::Span::call_site()),
293 field_ident: &syn::Ident::new("foo", ::proc_macro2::Span::call_site()),
294 field_type: BuilderFieldType::Optional(Box::leak(Box::new(parse_quote!(Foo)))),
295 generic_into: false,
296 strip_option: false,
297 each: None,
298 }
299 };
300 }
301
302 #[cfg(test)]
303 mod testsrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/ {
304 #[allow(unused_imports)]
305 use superrust-analyzer cargo derive_builder_core 0.20.2 setter/::*;
306
307 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
308 fn immutablerust-analyzer cargo derive_builder_core 0.20.2 setter/tests/immutable().() {
309 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
310 setter.patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern. = BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Immutablerust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Immutable#;
311
312 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
313 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
314 quoterust-analyzer cargo quote 1.0.47 quote!!(
315 #[allow(unused_mut)]
316 pub fn foo(&self, value: Foo) -> Self {
317 let mut new = ::db::export::core::clone::Clone::clone(self);
318 new.foo = ::db::export::core::option::Option::Some(value);
319 new
320 }
321 )
322 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
323 );
324 }
325
326 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
327 fn mutablerust-analyzer cargo derive_builder_core 0.20.2 setter/tests/mutable().() {
328 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
329 setter.patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern. = BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Mutablerust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Mutable#;
330
331 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
332 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
333 quoterust-analyzer cargo quote 1.0.47 quote!!(
334 #[allow(unused_mut)]
335 pub fn foo(&mut self, value: Foo) -> &mut Self {
336 let mut new = self;
337 new.foo = ::db::export::core::option::Option::Some(value);
338 new
339 }
340 )
341 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
342 );
343 }
344
345 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
346 fn ownedrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/owned().() {
347 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
348 setter.patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern. = BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Ownedrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Owned#;
349
350 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
351 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
352 quoterust-analyzer cargo quote 1.0.47 quote!!(
353 #[allow(unused_mut)]
354 pub fn foo(self, value: Foo) -> Self {
355 let mut new = self;
356 new.foo = ::db::export::core::option::Option::Some(value);
357 new
358 }
359 )
360 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
361 );
362 }
363
364 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
365 fn privaterust-analyzer cargo derive_builder_core 0.20.2 setter/tests/private().() {
366 let vis = Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(synrust-analyzer cargo syn 2.0.119 crate/::Visibilityrust-analyzer cargo syn 2.0.119 restriction/Visibility#::Inheritedrust-analyzer cargo syn 2.0.119 restriction/Visibility#Inherited#);
367
368 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
369 setter.visibilityrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#visibility. = vis;
370
371 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
372 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
373 quoterust-analyzer cargo quote 1.0.47 quote!!(
374 #[allow(unused_mut)]
375 fn foo(&mut self, value: Foo) -> &mut Self {
376 let mut new = self;
377 new.foo = ::db::export::core::option::Option::Some(value);
378 new
379 }
380 )
381 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
382 );
383 }
384
385 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
386 fn genericrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/generic().() {
387 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
388 setter.generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into. = true;
389
390 #[rustfmt::skip]
391 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
392 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
393 quoterust-analyzer cargo quote 1.0.47 quote!!(
394 #[allow(unused_mut)]
395 pub fn foo<VALUE: ::db::export::core::convert::Into<Foo>>(
396 &mut self,
397 value: VALUE
398 ) -> &mut Self {
399 let mut new = self;
400 new.foo = ::db::export::core::option::Option::Some(value.into());
401 new
402 }
403 )
404 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
405 );
406 }
407
408 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
409 fn strip_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/strip_option().() {
410 let ty = parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(Option<Foo>);
411 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
412 setter.strip_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#strip_option. = true;
413 setter.field_typerust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_type. = BuilderFieldTyperust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#::Optionalrust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#Optional#(&ty);
414
415 #[rustfmt::skip]
416 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
417 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
418 quoterust-analyzer cargo quote 1.0.47 quote!!(
419 #[allow(unused_mut)]
420 pub fn foo(&mut self, value: Foo) -> &mut Self {
421 let mut new = self;
422 new.foo = ::db::export::core::option::Option::Some(
423 ::db::export::core::option::Option::Some(value)
424 );
425 new
426 }
427 )
428 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
429 );
430 }
431
432 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
433 fn strip_option_intorust-analyzer cargo derive_builder_core 0.20.2 setter/tests/strip_option_into().() {
434 let ty = parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(Option<Foo>);
435 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
436 setter.strip_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#strip_option. = true;
437 setter.generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into. = true;
438 setter.field_typerust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_type. = BuilderFieldTyperust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#::Optionalrust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#Optional#(&ty);
439
440 #[rustfmt::skip]
441 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
442 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
443 quoterust-analyzer cargo quote 1.0.47 quote!!(
444 #[allow(unused_mut)]
445 pub fn foo<VALUE: ::db::export::core::convert::Into<Foo>>(
446 &mut self,
447 value: VALUE
448 ) -> &mut Self {
449 let mut new = self;
450 new.foo = ::db::export::core::option::Option::Some(
451 ::db::export::core::option::Option::Some(value.into())
452 );
453 new
454 }
455 )
456 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
457 );
458 }
459 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
460 fn strip_option_try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/strip_option_try_setter().() {
461 let ty = parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(Option<Foo>);
462 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
463 setter.strip_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#strip_option. = true;
464 setter.try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#try_setter. = true;
465 setter.generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into. = true;
466 setter.field_typerust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#field_type. = BuilderFieldTyperust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#::Optionalrust-analyzer cargo derive_builder_core 0.20.2 builder_field/BuilderFieldType#Optional#(&ty);
467 #[rustfmt::skip]
468 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
469 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
470 quoterust-analyzer cargo quote 1.0.47 quote!!(
471 #[allow(unused_mut)]
472 pub fn foo<VALUE: ::db::export::core::convert::Into<Foo>>(
473 &mut self,
474 value: VALUE
475 ) -> &mut Self {
476 let mut new = self;
477 new.foo = ::db::export::core::option::Option::Some(
478 ::db::export::core::option::Option::Some(value.into())
479 );
480 new
481 }
482 pub fn try_foo<VALUE: ::db::export::core::convert::TryInto<Foo>>(
483 &mut self,
484 value: VALUE
485 ) -> ::db::export::core::result::Result<&mut Self, VALUE::Error> {
486 let converted: Foo = value.try_into()?;
487 let mut new = self;
488 new.foo = ::db::export::core::option::Option::Some(
489 ::db::export::core::option::Option::Some(converted)
490 );
491 Ok(new)
492 }
493 )
494 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
495 );
496 }
497
498 // including try_setter
499 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
500 fn fullrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/full().() {
501 //named!(outer_attrs -> Vec<syn::Attribute>, many0!(syn::Attribute::parse_outer));
502 //let attrs = outer_attrs.parse_str("#[some_attr]").unwrap();
503 let attrs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<synrust-analyzer cargo syn 2.0.119 crate/::Attributerust-analyzer cargo syn 2.0.119 attr/Attribute#> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(#[some_attr])];
504
505 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
506 setter.attrsrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#attrs. = attrs.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().();
507 setter.generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into. = true;
508 setter.try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#try_setter. = true;
509
510 #[rustfmt::skip]
511 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
512 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
513 quoterust-analyzer cargo quote 1.0.47 quote!!(
514 #[some_attr]
515 #[allow(unused_mut)]
516 pub fn foo <VALUE: ::db::export::core::convert::Into<Foo>>(&mut self, value: VALUE) -> &mut Self {
517 let mut new = self;
518 new.foo = ::db::export::core::option::Option::Some(value.into());
519 new
520 }
521
522 #[some_attr]
523 pub fn try_foo<VALUE: ::db::export::core::convert::TryInto<Foo>>(&mut self, value: VALUE)
524 -> ::db::export::core::result::Result<&mut Self, VALUE::Error> {
525 let converted : Foo = value.try_into()?;
526 let mut new = self;
527 new.foo = ::db::export::core::option::Option::Some(converted);
528 Ok(new)
529 }
530 ).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
531 );
532 }
533
534 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
535 fn no_stdrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/no_std().() {
536 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
537 setter.patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern. = BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Immutablerust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Immutable#;
538
539 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
540 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
541 quoterust-analyzer cargo quote 1.0.47 quote!!(
542 #[allow(unused_mut)]
543 pub fn foo(&self, value: Foo) -> Self {
544 let mut new = ::db::export::core::clone::Clone::clone(self);
545 new.foo = ::db::export::core::option::Option::Some(value);
546 new
547 }
548 )
549 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
550 );
551 }
552
553 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
554 fn no_std_genericrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/no_std_generic().() {
555 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
556 setter.generic_intorust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#generic_into. = true;
557
558 #[rustfmt::skip]
559 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
560 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
561 quoterust-analyzer cargo quote 1.0.47 quote!!(
562 #[allow(unused_mut)]
563 pub fn foo<VALUE: ::db::export::core::convert::Into<Foo>>(
564 &mut self,
565 value: VALUE
566 ) -> &mut Self {
567 let mut new = self;
568 new.foo = ::db::export::core::option::Option::Some(value.into());
569 new
570 }
571 )
572 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
573 );
574 }
575
576 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
577 fn setter_disabledrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/setter_disabled().() {
578 let mut setter = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
579 setter.setter_enabledrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#setter_enabled. = false;
580
581 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), quoterust-analyzer cargo quote 1.0.47 quote!!().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
582 }
583
584 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
585 fn try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/tests/try_setter().() {
586 let mut setter: Setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter# = default_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/default_setter!!();
587 setter.patternrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#pattern. = BuilderPatternrust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#::Mutablerust-analyzer cargo derive_builder_core 0.20.2 options/BuilderPattern#Mutable#;
588 setter.try_setterrust-analyzer cargo derive_builder_core 0.20.2 setter/Setter#try_setter. = true;
589
590 #[rustfmt::skip]
591 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
592 quoterust-analyzer cargo quote 1.0.47 quote!!(#setter).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
593 quoterust-analyzer cargo quote 1.0.47 quote!!(
594 #[allow(unused_mut)]
595 pub fn foo(&mut self, value: Foo) -> &mut Self {
596 let mut new = self;
597 new.foo = ::db::export::core::option::Option::Some(value);
598 new
599 }
600
601 pub fn try_foo<VALUE: ::db::export::core::convert::TryInto<Foo>>(
602 &mut self,
603 value: VALUE
604 ) -> ::db::export::core::result::Result<&mut Self, VALUE::Error> {
605 let converted: Foo = value.try_into()?;
606 let mut new = self;
607 new.foo = ::db::export::core::option::Option::Some(converted);
608 Ok(new)
609 }
610 )
611 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
612 );
613 }
614
615 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
616 fn extract_type_from_option_on_simple_typerust-analyzer cargo derive_builder_core 0.20.2 setter/tests/extract_type_from_option_on_simple_type().() {
617 let ty_foo = parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(Foo);
618 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(extract_type_from_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_type_from_option().(&ty_foo), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
619
620 for s in vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
621 parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(Option<Foo>),
622 parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(std::option::Option<Foo>),
623 parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(::std::option::Option<Foo>),
624 parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(core::option::Option<Foo>),
625 parse_quoterust-analyzer cargo syn 2.0.119 parse_quote/parse_quote!!(::core::option::Option<Foo>),
626 ] {
627 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(extract_type_from_optionrust-analyzer cargo derive_builder_core 0.20.2 setter/extract_type_from_option().(&s), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&ty_foo));
628 }
629 }
630 }