Make use of #[doc] field attributes in Props derive macro (#2456)
* Support passing docs along to prop fields * Pass along entire doc attribute
This commit is contained in:
1 parent
d4ad579b72
commit
160cde7b48
1 file changed
+8
-14
@@ -271,7 +271,7 @@ mod field_info {
|
|||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct FieldBuilderAttr {
|
pub struct FieldBuilderAttr {
|
||||||
pub default: Option<syn::Expr>,
|
pub default: Option<syn::Expr>,
|
||||||
pub doc: Option<syn::Expr>,
|
pub docs: Vec<syn::Attribute>,
|
||||||
pub skip: bool,
|
pub skip: bool,
|
||||||
pub auto_into: bool,
|
pub auto_into: bool,
|
||||||
pub from_displayable: bool,
|
pub from_displayable: bool,
|
||||||
@@ -284,6 +284,11 @@ mod field_info {
|
|||||||
pub fn with(mut self, attrs: &[syn::Attribute]) -> Result<Self, Error> {
|
pub fn with(mut self, attrs: &[syn::Attribute]) -> Result<Self, Error> {
|
||||||
let mut skip_tokens = None;
|
let mut skip_tokens = None;
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
|
if attr.path().is_ident("doc") {
|
||||||
|
self.docs.push(attr.clone());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if path_to_single_string(attr.path()).as_deref() != Some("props") {
|
if path_to_single_string(attr.path()).as_deref() != Some("props") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -345,10 +350,6 @@ mod field_info {
|
|||||||
self.default = Some(*assign.right);
|
self.default = Some(*assign.right);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
"doc" => {
|
|
||||||
self.doc = Some(*assign.right);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
"default_code" => {
|
"default_code" => {
|
||||||
if let syn::Expr::Lit(syn::ExprLit {
|
if let syn::Expr::Lit(syn::ExprLit {
|
||||||
lit: syn::Lit::Str(code),
|
lit: syn::Lit::Str(code),
|
||||||
@@ -444,10 +445,6 @@ mod field_info {
|
|||||||
self.default = None;
|
self.default = None;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
"doc" => {
|
|
||||||
self.doc = None;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
"skip" => {
|
"skip" => {
|
||||||
self.skip = false;
|
self.skip = false;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1105,10 +1102,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
);
|
);
|
||||||
|
|
||||||
let (impl_generics, _, where_clause) = generics.split_for_impl();
|
let (impl_generics, _, where_clause) = generics.split_for_impl();
|
||||||
let doc = match field.builder_attr.doc {
|
let docs = &field.builder_attr.docs;
|
||||||
Some(ref doc) => quote!(#[doc = #doc]),
|
|
||||||
None => quote!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let arg_type = field_type;
|
let arg_type = field_type;
|
||||||
// If the field is auto_into, we need to add a generic parameter to the builder for specialization
|
// If the field is auto_into, we need to add a generic parameter to the builder for specialization
|
||||||
@@ -1161,7 +1155,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[allow(dead_code, non_camel_case_types, missing_docs)]
|
#[allow(dead_code, non_camel_case_types, missing_docs)]
|
||||||
impl #impl_generics #builder_name < #( #ty_generics ),* > #where_clause {
|
impl #impl_generics #builder_name < #( #ty_generics ),* > #where_clause {
|
||||||
#doc
|
#( #docs )*
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn #field_name < #marker > (self, #field_name: #arg_type) -> #builder_name < #( #target_generics ),* > {
|
pub fn #field_name < #marker > (self, #field_name: #arg_type) -> #builder_name < #( #target_generics ),* > {
|
||||||
let #field_name = (#arg_expr,);
|
let #field_name = (#arg_expr,);
|
||||||
|
|||||||
Reference in new issue
Block a user