@@ -664,7 +664,7 @@ impl<S, R> Spec<'_, S, R> {
664664 & self . diff_format
665665 }
666666
667- /// Returns the failing strategy that is used in case an assertion fails.
667+ /// Returns the failing strategy used in case an assertion fails.
668668 pub fn failing_strategy ( & self ) -> & R {
669669 & self . failing_strategy
670670 }
@@ -956,20 +956,6 @@ where
956956 {
957957 self . expecting ( satisfies ( predicate) . with_message ( message) )
958958 }
959-
960- /// Fails the assertion according to the current failing strategy of this
961- /// `Spec`.
962- #[ track_caller]
963- pub fn do_fail_with_message ( & mut self , message : impl Into < String > ) {
964- let message = message. into ( ) ;
965- let failure = AssertFailure {
966- description : self . description . clone ( ) . map ( String :: from) ,
967- message,
968- location : self . location . map ( OwnedLocation :: from) ,
969- } ;
970- self . failures . push ( failure) ;
971- self . failing_strategy . do_fail_with ( & self . failures ) ;
972- }
973959}
974960
975961impl < ' a , I , R > Spec < ' a , I , R > {
@@ -1140,9 +1126,44 @@ impl<'a, I, R> Spec<'a, I, R> {
11401126 }
11411127}
11421128
1129+ /// Trigger failing of an assertion according to the failing strategy of its
1130+ /// implementing spec-like struct.
1131+ pub trait DoFail {
1132+ /// Fails the assertion with the given [`AssertFailure`]s according to the
1133+ /// current failing strategy of the `Spec` or other implementing
1134+ /// spec-like struct.
1135+ fn do_fail_with ( & mut self , failures : impl IntoIterator < Item = AssertFailure > ) ;
1136+
1137+ /// Fails the assertion with the given failure message according to the
1138+ /// current failing strategy of the `Spec` or other implementing
1139+ /// spec-like struct.
1140+ fn do_fail_with_message ( & mut self , message : impl Into < String > ) ;
1141+ }
1142+
1143+ impl < S , R > DoFail for Spec < ' _ , S , R >
1144+ where
1145+ R : FailingStrategy ,
1146+ {
1147+ fn do_fail_with ( & mut self , failures : impl IntoIterator < Item = AssertFailure > ) {
1148+ self . failures . extend ( failures) ;
1149+ self . failing_strategy . do_fail_with ( & self . failures ) ;
1150+ }
1151+
1152+ fn do_fail_with_message ( & mut self , message : impl Into < String > ) {
1153+ let message = message. into ( ) ;
1154+ let failure = AssertFailure {
1155+ description : self . description . clone ( ) . map ( String :: from) ,
1156+ message,
1157+ location : self . location . map ( OwnedLocation :: from) ,
1158+ } ;
1159+ self . failures . push ( failure) ;
1160+ self . failing_strategy . do_fail_with ( & self . failures ) ;
1161+ }
1162+ }
1163+
11431164/// Turns assertions into "soft assertions".
11441165///
1145- /// see method [`soft_panic()`](SoftPanic::soft_panic) for details and how to
1166+ /// See method [`soft_panic()`](SoftPanic::soft_panic) for details and how to
11461167/// use it.
11471168pub trait SoftPanic {
11481169 /// Turns assertions into "soft assertions".
0 commit comments