@@ -372,12 +372,12 @@ impl Function {
372
372
Self :: Intersects ( Box :: new ( lhs. into ( ) ) , Box :: new ( rhs. into ( ) ) )
373
373
}
374
374
375
- pub fn new_in ( lhs : impl Into < Rule > , rhs : impl Into < Rule > ) -> Self {
376
- Self :: In ( Box :: new ( lhs . into ( ) ) , Box :: new ( rhs . into ( ) ) )
375
+ pub fn new_in ( array : impl Into < Rule > , value : impl Into < Rule > ) -> Self {
376
+ Self :: In ( Box :: new ( array . into ( ) ) , Box :: new ( value . into ( ) ) )
377
377
}
378
378
379
- pub fn new_nin ( lhs : impl Into < Rule > , rhs : impl Into < Rule > ) -> Self {
380
- Self :: Nin ( Box :: new ( lhs . into ( ) ) , Box :: new ( rhs . into ( ) ) )
379
+ pub fn new_nin ( array : impl Into < Rule > , value : impl Into < Rule > ) -> Self {
380
+ Self :: Nin ( Box :: new ( array . into ( ) ) , Box :: new ( value . into ( ) ) )
381
381
}
382
382
383
383
pub fn new_between (
@@ -888,101 +888,105 @@ fn eval(input: &Input, output: &mut Output, rule: &Rule) -> Result<Option<Value>
888
888
889
889
Some ( Value :: Bool ( a. iter ( ) . any ( |x| b. contains ( x) ) ) )
890
890
}
891
- Function :: In ( first_rule , second_rule ) => {
892
- let a = eval ( input, output, first_rule ) ?. ok_or ( Error :: TypeError ) ?;
893
- let b = eval ( input , output , second_rule ) ?
894
- . ok_or ( Error :: TypeError ) ?
895
- . try_array ( ) ?;
891
+ Function :: In ( array_value , search_value ) => {
892
+ let a = eval ( input, output, array_value ) ?. ok_or ( Error :: TypeError ) ?
893
+ . try_array ( ) ? ;
894
+ let b = eval ( input , output , search_value ) ?
895
+ . ok_or ( Error :: TypeError ) ?;
896
896
897
- Some ( Value :: Bool ( b . contains ( & a ) ) )
897
+ Some ( Value :: Bool ( a . contains ( & b ) ) )
898
898
}
899
- Function :: Nin ( first_rule , second_rule ) => {
900
- let is_in = Function :: In ( first_rule . clone ( ) , second_rule . clone ( ) )
899
+ Function :: Nin ( array_value , search_value ) => {
900
+ let is_in = Function :: In ( array_value . clone ( ) , search_value . clone ( ) )
901
901
. eval ( input, output) ?
902
902
. ok_or ( Error :: TypeError ) ?
903
903
. try_bool ( ) ?;
904
904
Some ( Value :: Bool ( !is_in) )
905
905
}
906
- Function :: Between ( first_rule , second_rule , third_rule ) => {
907
- let is_gte_start = Function :: Gte ( first_rule . clone ( ) , second_rule . clone ( ) )
906
+ Function :: Between ( value_rule , min_rule , max_rule ) => {
907
+ let is_gte_start = Function :: Gte ( value_rule . clone ( ) , min_rule . clone ( ) )
908
908
. eval ( input, output) ?
909
909
. ok_or ( Error :: TypeError ) ?
910
910
. try_bool ( ) ?;
911
911
912
- let is_lte_end = Function :: Lte ( first_rule . clone ( ) , third_rule . clone ( ) )
912
+ let is_lte_end = Function :: Lte ( value_rule . clone ( ) , max_rule . clone ( ) )
913
913
. eval ( input, output) ?
914
914
. ok_or ( Error :: TypeError ) ?
915
915
. try_bool ( ) ?;
916
+
916
917
Some ( Value :: Bool ( is_gte_start && is_lte_end) )
917
918
}
918
- Function :: At ( first_rule , second_rule ) => {
919
- let mut first_eval = first_rule
919
+ Function :: At ( array_rule , index_rule ) => {
920
+ let mut array_value = array_rule
920
921
. eval ( input, output) ?
921
922
. ok_or ( Error :: TypeError ) ?
922
923
. try_array ( ) ?;
923
- let second_eval = second_rule
924
+ let index_value = index_rule
924
925
. eval ( input, output) ?
925
926
. ok_or ( Error :: TypeError ) ?
926
927
. try_number ( ) ?
927
928
. as_u64 ( )
928
929
. ok_or ( Error :: TypeError ) ?;
929
- let index = usize:: try_from ( second_eval) . map_err ( |_| Error :: TypeError ) ?;
930
- if first_eval. get ( index) . is_none ( ) {
930
+ let index = usize:: try_from ( index_value) . map_err ( |_| Error :: TypeError ) ?;
931
+
932
+ if array_value. get ( index) . is_none ( ) {
931
933
return Err ( Error :: TypeError ) ;
932
934
} else {
933
- Some ( first_eval . swap_remove ( index) )
935
+ Some ( array_value . swap_remove ( index) )
934
936
}
935
937
}
936
- Function :: Split ( first_rule , second_rule ) => {
937
- let first_eval = first_rule
938
+ Function :: Split ( string_rule , pattern_rule ) => {
939
+ let string_value = string_rule
938
940
. eval ( input, output) ?
939
941
. ok_or ( Error :: TypeError ) ?
940
942
. try_string ( ) ?;
941
- let second_eval = second_rule
943
+ let pattern_value = pattern_rule
942
944
. eval ( input, output) ?
943
945
. ok_or ( Error :: TypeError ) ?
944
946
. try_string ( ) ?;
945
947
946
- let after_split = first_eval
947
- . split ( & second_eval )
948
+ let after_split = string_value
949
+ . split ( & pattern_value )
948
950
. map ( Value :: new_string)
949
951
. collect ( ) ;
952
+
950
953
Some ( Value :: Array ( after_split) )
951
954
}
952
- Function :: StartsWith ( first_rule , second_rule ) => {
953
- let first_eval = first_rule
955
+ Function :: StartsWith ( string_rule , starts_with_rule ) => {
956
+ let string_value = string_rule
954
957
. eval ( input, output) ?
955
958
. ok_or ( Error :: TypeError ) ?
956
959
. try_string ( ) ?;
957
- let second_eval = second_rule
960
+ let starts_with_value = starts_with_rule
958
961
. eval ( input, output) ?
959
962
. ok_or ( Error :: TypeError ) ?
960
963
. try_string ( ) ?;
961
964
962
- Some ( Value :: Bool ( first_eval . starts_with ( & second_eval ) ) )
965
+ Some ( Value :: Bool ( string_value . starts_with ( & starts_with_value ) ) )
963
966
}
964
- Function :: EndsWith ( first_rule , second_rule ) => {
965
- let first_eval = first_rule
967
+ Function :: EndsWith ( string_rule , ends_with_rule ) => {
968
+ let string_value = string_rule
966
969
. eval ( input, output) ?
967
970
. ok_or ( Error :: TypeError ) ?
968
971
. try_string ( ) ?;
969
- let second_eval = second_rule
972
+ let ends_with_value = ends_with_rule
970
973
. eval ( input, output) ?
971
974
. ok_or ( Error :: TypeError ) ?
972
975
. try_string ( ) ?;
973
976
974
- Some ( Value :: Bool ( first_eval . ends_with ( & second_eval ) ) )
977
+ Some ( Value :: Bool ( string_value . ends_with ( & ends_with_value ) ) )
975
978
}
976
- Function :: OnlyShowIf ( first_rule ) => {
977
- let first_eval = first_rule
979
+ Function :: OnlyShowIf ( rule ) => {
980
+ let eval = rule
978
981
. eval ( input, output) ?
979
982
. ok_or ( Error :: TypeError ) ?
980
983
. try_bool ( ) ?;
981
- let new_rule = Box :: new ( Rule :: Value ( Value :: Bool ( first_eval) ) ) ;
984
+ let new_rule = Box :: new ( Rule :: Value ( Value :: Bool ( eval) ) ) ;
985
+
982
986
Function :: Set ( String :: from ( "show" ) , new_rule) . eval ( input, output) ?
983
987
}
984
- Function :: GetPriceInUsd ( first_rule ) => {
985
- let amount = first_rule
988
+ Function :: GetPriceInUsd ( amount_rule ) => {
989
+ let amount = amount_rule
986
990
. eval ( input, output) ?
987
991
. ok_or ( Error :: TypeError ) ?
988
992
. try_bignum ( ) ?;
0 commit comments