Hi Community !
I want to add conditional string to the #[doc] attr which generated in the macros:
#[macro_export]
macro_rules! fields {
(
$(#[$enum_attr:meta])*
pub enum $enum_name:ident {
$(
$(#[$variant_attr:meta])*
$field_type:ident $(( $($custom_types:ident),+ ))?
$([$len:expr])? $variant:ident = $start_index:expr$(,)?
)*
}
) => {
$(#[$enum_attr])*
#[derive(Serialize, Ord, PartialOrd, Eq, PartialEq, Clone, Debug)]
#[allow(dead_code)]
pub enum $enum_name {
$(
$(#[$variant_attr])*
#[doc = stringify!(FieldValue::$field_type)$(if $len >= 1 {stringify!(Array)})?]
$variant,
)*
}
// ... rest code
here I expect "Array" word will be added to the end if $len
param exists. Otherwise there will be a string without "Array" in it. The usage of the macro:
fields! {
pub enum ObjectField {
Long Guid = 0,
Integer Type = 2,
Integer Entry = 3,
Float ScaleX = 4,
Long[2] ArrayField = 5,
}
}
but if I try to add this string using this code:
#[doc = stringify!(FieldValue::$field_type)$(if $len >= 1 {stringify!(Array)})?]
I got an error:
error: expected one of `.`, `?`, `]`, or an operator, found keyword `if`
--> src/primary/traits/src/types/update_fields.rs:25:62
|
25 | #[doc = stringify!(FieldValue::$field_type)$(if $len >= 1 {stringify!(Array)})?]
| ^^ expected one of `.`, `?`, `]`, or an operator
could somebody explain, how can I fix this ?