@@ -88,6 +88,8 @@ pub struct Attributes {
8888 module : Vec < ( String , String ) > ,
8989 /// `struct` attributes.
9090 structure : Vec < ( String , String ) > ,
91+ /// `trait` attributes.
92+ trait_attributes : Vec < ( String , String ) > ,
9193}
9294
9395impl Attributes {
@@ -99,6 +101,10 @@ impl Attributes {
99101 generate_attributes ( name, & self . structure )
100102 }
101103
104+ fn for_trait ( & self , name : & str ) -> Vec < syn:: Attribute > {
105+ generate_attributes ( name, & self . trait_attributes )
106+ }
107+
102108 /// Add an attribute that will be added to `mod` items matching the given pattern.
103109 ///
104110 /// # Examples
@@ -124,6 +130,19 @@ impl Attributes {
124130 pub fn push_struct ( & mut self , pattern : impl Into < String > , attr : impl Into < String > ) {
125131 self . structure . push ( ( pattern. into ( ) , attr. into ( ) ) ) ;
126132 }
133+
134+ /// Add an attribute that will be added to `trait` items matching the given pattern.
135+ ///
136+ /// # Examples
137+ ///
138+ /// ```
139+ /// # use tonic_build::*;
140+ /// let mut attributes = Attributes::default();
141+ /// attributes.push_trait("Server", "#[mockall::automock]");
142+ /// ```
143+ pub fn push_trait ( & mut self , pattern : impl Into < String > , attr : impl Into < String > ) {
144+ self . trait_attributes . push ( ( pattern. into ( ) , attr. into ( ) ) ) ;
145+ }
127146}
128147
129148fn format_service_name < T : Service > ( service : & T , emit_package : bool ) -> String {
0 commit comments