@@ -267,7 +267,7 @@ struct RawSwitchRule {
267267 value_type : Option < SwitchPropertyType > ,
268268
269269 #[ serde( default , rename = "v2" ) ]
270- value2 : Option < Variant > ,
270+ value2 : Variant ,
271271
272272 #[ serde( default , rename = "v2t" ) ]
273273 value2_type : Option < SwitchPropertyType > ,
@@ -284,7 +284,7 @@ struct SwitchRule {
284284
285285 value_type : SwitchPropertyType ,
286286
287- value2 : Option < RedPropertyValue > ,
287+ value2 : RedPropertyValue ,
288288
289289 value2_type : Option < SwitchPropertyType > ,
290290
@@ -357,27 +357,29 @@ impl SwitchNode {
357357 ( None , None ) => ( SwitchPropertyType :: Str , RedPropertyValue :: null ( ) ) ,
358358 } ;
359359
360- let ( v2t, v2) = if let Some ( raw_v2 ) = raw_rule. value2 {
360+ let ( v2t, v2) = if ! raw_rule. value2 . is_null ( ) {
361361 match raw_rule. value2_type {
362- Some ( SwitchPropertyType :: Prev ) => ( Some ( SwitchPropertyType :: Prev ) , Some ( RedPropertyValue :: null ( ) ) ) ,
362+ Some ( SwitchPropertyType :: Prev ) => ( Some ( SwitchPropertyType :: Prev ) , RedPropertyValue :: null ( ) ) ,
363363 None => {
364- if raw_v2 . is_number ( ) {
365- ( Some ( SwitchPropertyType :: Num ) , Some ( RedPropertyValue :: Constant ( raw_v2 ) ) )
364+ if raw_rule . value2 . is_number ( ) {
365+ ( Some ( SwitchPropertyType :: Num ) , RedPropertyValue :: Constant ( raw_rule . value2 ) )
366366 } else {
367- ( Some ( SwitchPropertyType :: Str ) , Some ( RedPropertyValue :: Constant ( raw_v2 ) ) )
367+ ( Some ( SwitchPropertyType :: Str ) , RedPropertyValue :: Constant ( raw_rule . value2 ) )
368368 }
369369 }
370370 Some ( raw_v2t) => {
371371 if raw_v2t. is_constant ( ) {
372- let evaluated = RedPropertyValue :: evaluate_constant ( & raw_v2, raw_v2t. try_into ( ) ?) ?;
373- ( Some ( raw_v2t) , Some ( evaluated) )
372+ (
373+ Some ( raw_v2t) ,
374+ RedPropertyValue :: evaluate_constant ( & raw_rule. value2 , raw_v2t. try_into ( ) ?) ?,
375+ )
374376 } else {
375- ( Some ( raw_v2t) , Some ( RedPropertyValue :: Runtime ( raw_v2 . to_string ( ) ?) ) )
377+ ( Some ( raw_v2t) , RedPropertyValue :: Runtime ( raw_rule . value2 . to_string ( ) ?) )
376378 }
377379 }
378380 }
379381 } else {
380- ( raw_rule. value2_type , Some ( RedPropertyValue :: null ( ) ) )
382+ ( raw_rule. value2_type , RedPropertyValue :: null ( ) )
381383 } ;
382384
383385 let v = match v {
@@ -474,7 +476,7 @@ impl SwitchNode {
474476 async fn get_v2 ( & self , rule : & SwitchRule , msg : & Msg ) -> crate :: Result < Variant > {
475477 match ( rule. value2_type , & rule. value2 ) {
476478 ( Some ( SwitchPropertyType :: Prev ) , _) => Ok ( self . prev_value . read ( ) . await . clone ( ) ) ,
477- ( Some ( vt2) , Some ( v2 ) ) => {
479+ ( Some ( vt2) , v2 ) => {
478480 eval:: evaluate_node_property_value (
479481 v2. clone ( ) ,
480482 vt2. try_into ( ) . unwrap ( ) ,
@@ -485,7 +487,6 @@ impl SwitchNode {
485487 . await
486488 }
487489 ( None , _) => Ok ( Variant :: Null ) ,
488- _ => Err ( EdgelinkError :: BadArgument ( "rule" ) . into ( ) ) ,
489490 }
490491 }
491492}
0 commit comments