mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
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:
parent
d4ad579b72
commit
160cde7b48
1 changed files with 8 additions and 14 deletions
|
@ -271,7 +271,7 @@ mod field_info {
|
|||
#[derive(Debug, Default, Clone)]
|
||||
pub struct FieldBuilderAttr {
|
||||
pub default: Option<syn::Expr>,
|
||||
pub doc: Option<syn::Expr>,
|
||||
pub docs: Vec<syn::Attribute>,
|
||||
pub skip: bool,
|
||||
pub auto_into: bool,
|
||||
pub from_displayable: bool,
|
||||
|
@ -284,6 +284,11 @@ mod field_info {
|
|||
pub fn with(mut self, attrs: &[syn::Attribute]) -> Result<Self, Error> {
|
||||
let mut skip_tokens = None;
|
||||
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") {
|
||||
continue;
|
||||
}
|
||||
|
@ -345,10 +350,6 @@ mod field_info {
|
|||
self.default = Some(*assign.right);
|
||||
Ok(())
|
||||
}
|
||||
"doc" => {
|
||||
self.doc = Some(*assign.right);
|
||||
Ok(())
|
||||
}
|
||||
"default_code" => {
|
||||
if let syn::Expr::Lit(syn::ExprLit {
|
||||
lit: syn::Lit::Str(code),
|
||||
|
@ -444,10 +445,6 @@ mod field_info {
|
|||
self.default = None;
|
||||
Ok(())
|
||||
}
|
||||
"doc" => {
|
||||
self.doc = None;
|
||||
Ok(())
|
||||
}
|
||||
"skip" => {
|
||||
self.skip = false;
|
||||
Ok(())
|
||||
|
@ -1105,10 +1102,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|||
);
|
||||
|
||||
let (impl_generics, _, where_clause) = generics.split_for_impl();
|
||||
let doc = match field.builder_attr.doc {
|
||||
Some(ref doc) => quote!(#[doc = #doc]),
|
||||
None => quote!(),
|
||||
};
|
||||
let docs = &field.builder_attr.docs;
|
||||
|
||||
let arg_type = field_type;
|
||||
// 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! {
|
||||
#[allow(dead_code, non_camel_case_types, missing_docs)]
|
||||
impl #impl_generics #builder_name < #( #ty_generics ),* > #where_clause {
|
||||
#doc
|
||||
#( #docs )*
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn #field_name < #marker > (self, #field_name: #arg_type) -> #builder_name < #( #target_generics ),* > {
|
||||
let #field_name = (#arg_expr,);
|
||||
|
|
Loading…
Reference in a new issue