📝 Add doc comments for builder pattern functions
This commit is contained in:
parent
9e4f593dbd
commit
2389aad546
1 changed files with 14 additions and 1 deletions
|
|
@ -45,19 +45,32 @@ pub fn fn_with(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let fn_with_name = fn_name.replace("alter_", "with_");
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let fn_with = parse_str::<ItemFn>(concat_string!("
|
let fn_with = parse_str::<ItemFn>(concat_string!("
|
||||||
pub fn ", fn_name.replace("alter_", "with_"), "(mut self, ", args.join(", "), ") -> Self {
|
pub fn ", fn_with_name, "(mut self, ", args.join(", "), ") -> Self {
|
||||||
self.", fn_name, "(", param.join(", "), ");
|
self.", fn_name, "(", param.join(", "), ");
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
").as_str()).unwrap();
|
").as_str()).unwrap();
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let fn_alter_doc = concat_string!(
|
||||||
|
"<p id=\"method.", fn_with_name, "\">",
|
||||||
|
"Use <code class=\"code-header\"> <a class=\"fn\" href=\"#method.", fn_with_name, "\">",
|
||||||
|
fn_with_name,
|
||||||
|
"</a>(self, …) -> Self </code> to apply the <a href=\"#method.new\">builder pattern</a>.",
|
||||||
|
"</p>"
|
||||||
|
);
|
||||||
|
|
||||||
let fn_alter = fn_item.into_token_stream();
|
let fn_alter = fn_item.into_token_stream();
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
|
#[doc(hidden)]
|
||||||
#fn_with
|
#fn_with
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[doc = #fn_alter_doc]
|
||||||
#fn_alter
|
#fn_alter
|
||||||
};
|
};
|
||||||
expanded.into()
|
expanded.into()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue