I worked around this by manually implementing PartialEq and Eq, however I ran into a case where Rust needs #[derive(...)] to be used as constants within match statement:= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!= note: for more information, see RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>推荐答案您提供的完整示例"链接确实显示了具有宏前缀属性的示例(请参见第二个宏). /p>The "complete example" link you provide does show an example of having the macro prefix attributes (see the second macro). #[derive(PartialEq, Eq, Copy, Clone, Debug)] $struct_p_def但是,如果相反,您希望能够为每个结构提供派生属性(例如,仅某些结构需要派生PartialEq),则可以在第二个 example—属性被视为item宏形式的一部分.例如However, if instead you want to be able to provide derive-attributes per struct (e.g., only some of your structs need to derive PartialEq), you can pass the derive expression in the first part of your second struct_impl_my_features! example—the attributes are considered part of the item macro form. E.g.,struct_impl_my_features!( #[derive(PartialEq, Eq)] pub struct MyTypedNumber(pub u32);, MyTypedNumber); 更新对不起,对于您的主要问题,我没有答案.据我所知,这是不可能的.但是,如果您最关心的是笨拙,并且结构都具有相似的形式,则可以通过将其添加到宏的顶部来使宏调用更好:Sorry, I don't have an answer to your main question; as far as I know, it is not possible. However, if your primary concern is the clunkiness, and if your structs are all of similar form, you could make your macro call nicer by adding this to the top of your macro:($x:ident ( $($v:tt)* ) ) => { struct_impl_my_features!(pub struct $x( $($v)* );, $x)};然后像这样调用它:struct_impl_my_features!(MyTypedNumber(pub u32)); 这篇关于可以在结构声明之后*派生属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-22 18:18