File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
cargo_pup_lint_config/src/struct_lint Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,22 @@ impl<'a> StructConstraintBuilder<'a> {
127127 self
128128 }
129129
130+ /// Add a rule requiring the struct to implement a given trait
131+ pub fn must_implement_trait ( mut self , trait_path : impl Into < String > ) -> Self {
132+ self . add_rule_internal ( StructRule :: ImplementsTrait (
133+ trait_path. into ( ) ,
134+ self . current_severity ,
135+ ) ) ;
136+ self
137+ }
138+
139+ /// Add a rule requiring the struct NOT to implement a given trait
140+ pub fn must_not_implement_trait ( mut self , trait_path : impl Into < String > ) -> Self {
141+ let inner = StructRule :: ImplementsTrait ( trait_path. into ( ) , self . current_severity ) ;
142+ self . add_rule_internal ( StructRule :: Not ( Box :: new ( inner) ) ) ;
143+ self
144+ }
145+
130146 /// Add a rule requiring the struct to have public visibility
131147 pub fn must_be_public ( mut self ) -> Self {
132148 self . add_rule_internal ( StructRule :: MustBePublic ( self . current_severity ) ) ;
Original file line number Diff line number Diff line change @@ -82,11 +82,11 @@ fn test_lint_config() {
8282 // Trait restrictions
8383 builder. struct_lint ( )
8484 . lint_named ( "trait_restrictions" )
85- . matching ( |m|
86- m. implements_trait ( "^test_app::trait_impl::MyTrait$" ) )
85+ . matching ( |m| m. implements_trait ( "^test_app::trait_impl::MyTrait$" ) )
8786 . with_severity ( Severity :: Warn )
88- . must_be_named ( ".*MyTraitImpl$" . into ( ) )
87+ . must_be_named ( ".*MyTraitImpl$" . into ( ) )
8988 . must_be_private ( )
89+ . must_implement_trait ( "test_app::trait_impl::MyTrait" )
9090 . build ( ) ;
9191
9292 // Result error implementation check
You can’t perform that action at this time.
0 commit comments