🧑💻 Depura atributos #[inline] en builder_fn
This commit is contained in:
parent
8912bbc8ec
commit
6d6c0f874b
1 changed files with 16 additions and 5 deletions
|
|
@ -266,10 +266,13 @@ pub fn builder_fn(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
v
|
v
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extrae atributos descartando la documentación para incluir en `alter_...()`.
|
// Filtra los atributos descartando `#[doc]` y `#[inline]` para el método `alter_...()`.
|
||||||
let non_doc_attrs: Vec<_> = attrs
|
let non_doc_or_inline_attrs: Vec<_> = attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&a| !a.path().is_ident("doc"))
|
.filter(|a| {
|
||||||
|
let p = a.path();
|
||||||
|
!p.is_ident("doc") && !p.is_ident("inline")
|
||||||
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
@ -284,14 +287,21 @@ pub fn builder_fn(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
fn #with_name #generics (self, #(#args),*) -> Self #where_clause;
|
fn #with_name #generics (self, #(#args),*) -> Self #where_clause;
|
||||||
|
|
||||||
#(#non_doc_attrs)*
|
#(#non_doc_or_inline_attrs)*
|
||||||
#[doc = #alter_doc]
|
#[doc = #alter_doc]
|
||||||
fn #alter_ident #generics (&mut self, #(#args),*) -> &mut Self #where_clause;
|
fn #alter_ident #generics (&mut self, #(#args),*) -> &mut Self #where_clause;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(body) => {
|
Some(body) => {
|
||||||
|
// Si no se indicó ninguna forma de `inline`, fuerza `#[inline]` para `with_...()`.
|
||||||
|
let force_inline = if attrs.iter().any(|a| a.path().is_ident("inline")) {
|
||||||
|
quote! {}
|
||||||
|
} else {
|
||||||
|
quote! { #[inline] }
|
||||||
|
};
|
||||||
let with_fn = if is_trait {
|
let with_fn = if is_trait {
|
||||||
quote! {
|
quote! {
|
||||||
|
#force_inline
|
||||||
#vis_pub fn #with_name #generics (self, #(#args),*) -> Self #where_clause {
|
#vis_pub fn #with_name #generics (self, #(#args),*) -> Self #where_clause {
|
||||||
let mut s = self;
|
let mut s = self;
|
||||||
s.#alter_ident(#(#call_idents),*);
|
s.#alter_ident(#(#call_idents),*);
|
||||||
|
|
@ -300,6 +310,7 @@ pub fn builder_fn(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
|
#force_inline
|
||||||
#vis_pub fn #with_name #generics (mut self, #(#args),*) -> Self #where_clause {
|
#vis_pub fn #with_name #generics (mut self, #(#args),*) -> Self #where_clause {
|
||||||
self.#alter_ident(#(#call_idents),*);
|
self.#alter_ident(#(#call_idents),*);
|
||||||
self
|
self
|
||||||
|
|
@ -310,7 +321,7 @@ pub fn builder_fn(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#with_fn
|
#with_fn
|
||||||
|
|
||||||
#(#non_doc_attrs)*
|
#(#non_doc_or_inline_attrs)*
|
||||||
#[doc = #alter_doc]
|
#[doc = #alter_doc]
|
||||||
#vis_pub fn #alter_ident #generics (&mut self, #(#args),*) -> &mut Self #where_clause {
|
#vis_pub fn #alter_ident #generics (&mut self, #(#args),*) -> &mut Self #where_clause {
|
||||||
#body
|
#body
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue