@@ -14,11 +14,39 @@ pub struct Condition {
1414 pub ( crate ) conditions : Vec < ConditionExpression > ,
1515}
1616
17- pub trait IntoCondition {
18- fn into_condition ( self ) -> Condition ;
17+ pub type Cond = Condition ;
18+
19+ impl From < Expr > for Condition {
20+ fn from ( expr : Expr ) -> Self {
21+ Condition {
22+ negate : false ,
23+ condition_type : ConditionType :: All ,
24+ conditions : vec ! [ ConditionExpression :: Expr ( expr) ] ,
25+ }
26+ }
1927}
2028
21- pub type Cond = Condition ;
29+ impl From < ConditionExpression > for Condition {
30+ fn from ( ce : ConditionExpression ) -> Self {
31+ Condition {
32+ negate : false ,
33+ condition_type : ConditionType :: All ,
34+ conditions : vec ! [ ce] ,
35+ }
36+ }
37+ }
38+
39+ /// A helper trait.
40+ ///
41+ /// You shouldn't implement this manually.
42+ pub trait IntoCondition : Into < Condition > {
43+ #[ inline( always) ]
44+ fn into_condition ( self ) -> Condition {
45+ self . into ( )
46+ }
47+ }
48+
49+ impl < T > IntoCondition for T where T : Into < Condition > { }
2250
2351/// An internal representation of conditions.
2452/// May be refactored away in the future if we can get our head around it.
@@ -310,26 +338,6 @@ impl From<Expr> for ConditionExpression {
310338 }
311339}
312340
313- impl From < Expr > for Condition {
314- fn from ( condition : Expr ) -> Self {
315- Condition {
316- negate : false ,
317- condition_type : ConditionType :: All ,
318- conditions : vec ! [ ConditionExpression :: Expr ( condition) ] ,
319- }
320- }
321- }
322-
323- impl From < ConditionExpression > for Condition {
324- fn from ( ce : ConditionExpression ) -> Self {
325- Condition {
326- negate : false ,
327- condition_type : ConditionType :: All ,
328- conditions : vec ! [ ce] ,
329- }
330- }
331- }
332-
333341/// Macro to easily create an [`Condition::any`].
334342///
335343/// # Examples
@@ -613,18 +621,6 @@ pub trait ConditionalStatement {
613621 C : IntoCondition ;
614622}
615623
616- impl IntoCondition for Expr {
617- fn into_condition ( self ) -> Condition {
618- Condition :: all ( ) . add ( self )
619- }
620- }
621-
622- impl IntoCondition for Condition {
623- fn into_condition ( self ) -> Condition {
624- self
625- }
626- }
627-
628624impl ConditionHolder {
629625 pub fn new ( ) -> Self {
630626 Self :: default ( )
0 commit comments