|
@@ -173,7 +173,7 @@ mod field_info {
|
|
use quote::quote;
|
|
use quote::quote;
|
|
use syn::spanned::Spanned;
|
|
use syn::spanned::Spanned;
|
|
use syn::{parse::Error, punctuated::Punctuated};
|
|
use syn::{parse::Error, punctuated::Punctuated};
|
|
- use syn::{Expr, Path};
|
|
|
|
|
|
+ use syn::{parse_quote, Expr, Path};
|
|
|
|
|
|
use super::util::{
|
|
use super::util::{
|
|
expr_to_single_string, ident_to_type, path_to_single_string, strip_raw_ident_prefix,
|
|
expr_to_single_string, ident_to_type, path_to_single_string, strip_raw_ident_prefix,
|
|
@@ -204,6 +204,15 @@ mod field_info {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // String fields automatically use impl Display
|
|
|
|
+ if field.ty == parse_quote!(::std::string::String)
|
|
|
|
+ || field.ty == parse_quote!(std::string::String)
|
|
|
|
+ || field.ty == parse_quote!(string::String)
|
|
|
|
+ || field.ty == parse_quote!(String)
|
|
|
|
+ {
|
|
|
|
+ builder_attr.from_displayable = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
// extended field is automatically empty
|
|
// extended field is automatically empty
|
|
if !builder_attr.extends.is_empty() {
|
|
if !builder_attr.extends.is_empty() {
|
|
builder_attr.default = Some(
|
|
builder_attr.default = Some(
|
|
@@ -263,6 +272,7 @@ mod field_info {
|
|
pub doc: Option<syn::Expr>,
|
|
pub doc: Option<syn::Expr>,
|
|
pub skip: bool,
|
|
pub skip: bool,
|
|
pub auto_into: bool,
|
|
pub auto_into: bool,
|
|
|
|
+ pub from_displayable: bool,
|
|
pub strip_option: bool,
|
|
pub strip_option: bool,
|
|
pub ignore_option: bool,
|
|
pub ignore_option: bool,
|
|
pub extends: Vec<Path>,
|
|
pub extends: Vec<Path>,
|
|
@@ -412,6 +422,7 @@ mod field_info {
|
|
handle_fields!(
|
|
handle_fields!(
|
|
"skip", skip, "skipped";
|
|
"skip", skip, "skipped";
|
|
"into", auto_into, "calling into() on the argument";
|
|
"into", auto_into, "calling into() on the argument";
|
|
|
|
+ "displayable", from_displayable, "calling to_string() on the argument";
|
|
"strip_option", strip_option, "putting the argument in Some(...)";
|
|
"strip_option", strip_option, "putting the argument in Some(...)";
|
|
)
|
|
)
|
|
}
|
|
}
|
|
@@ -443,6 +454,10 @@ mod field_info {
|
|
self.auto_into = false;
|
|
self.auto_into = false;
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
+ "displayable" => {
|
|
|
|
+ self.from_displayable = false;
|
|
|
|
+ Ok(())
|
|
|
|
+ }
|
|
"optional" => {
|
|
"optional" => {
|
|
self.strip_option = false;
|
|
self.strip_option = false;
|
|
self.ignore_option = true;
|
|
self.ignore_option = true;
|
|
@@ -954,6 +969,11 @@ Finally, call `.build()` to create the instance of `{name}`.
|
|
quote!(impl ::core::convert::Into<#arg_type>),
|
|
quote!(impl ::core::convert::Into<#arg_type>),
|
|
quote!(#field_name.into()),
|
|
quote!(#field_name.into()),
|
|
)
|
|
)
|
|
|
|
+ } else if field.builder_attr.from_displayable {
|
|
|
|
+ (
|
|
|
|
+ quote!(impl ::core::fmt::Display),
|
|
|
|
+ quote!(#field_name.to_string()),
|
|
|
|
+ )
|
|
} else {
|
|
} else {
|
|
(quote!(#arg_type), quote!(#field_name))
|
|
(quote!(#arg_type), quote!(#field_name))
|
|
};
|
|
};
|