@@ -944,7 +944,9 @@ pub struct StringConstraint {
944944impl StringConstraint {
945945 /// Any string allowed (empty slice = no restriction)
946946 pub const fn unconstrained ( ) -> Self {
947- Self { allowed_values : & [ ] }
947+ Self {
948+ allowed_values : & [ ] ,
949+ }
948950 }
949951
950952 /// String must be one of the specified values
@@ -1137,9 +1139,9 @@ impl ParamConstraint {
11371139 number : TypeConstraint :: Forbidden ,
11381140 string : TypeConstraint :: Constrained ( StringConstraint :: one_of ( values) ) ,
11391141 boolean : TypeConstraint :: Forbidden ,
1140- array : TypeConstraint :: Constrained ( ArrayConstraint :: of_strings ( StringConstraint :: one_of (
1141- values,
1142- ) ) ) ,
1142+ array : TypeConstraint :: Constrained ( ArrayConstraint :: of_strings (
1143+ StringConstraint :: one_of ( values) ,
1144+ ) ) ,
11431145 allow_null : true ,
11441146 }
11451147 }
@@ -1251,7 +1253,11 @@ fn validate_string(name: &str, s: &str, c: &StringConstraint) -> Result<(), Stri
12511253 return Ok ( ( ) ) ;
12521254 }
12531255 if !c. allowed_values . contains ( & s) {
1254- let quoted: Vec < String > = c. allowed_values . iter ( ) . map ( |v| format ! ( "'{}'" , v) ) . collect ( ) ;
1256+ let quoted: Vec < String > = c
1257+ . allowed_values
1258+ . iter ( )
1259+ . map ( |v| format ! ( "'{}'" , v) )
1260+ . collect ( ) ;
12551261 return Err ( format ! (
12561262 "Invalid value '{}' for '{}'. Allowed: {}" ,
12571263 s,
@@ -1837,26 +1843,34 @@ mod tests {
18371843 #[ test]
18381844 fn test_number_constraint_rejects_wrong_type ( ) {
18391845 let constraint = ParamConstraint :: number_min ( 0.0 ) ;
1840- let result =
1841- validate_parameter ( "test" , & ParameterValue :: String ( "hello" . to_string ( ) ) , & constraint) ;
1846+ let result = validate_parameter (
1847+ "test" ,
1848+ & ParameterValue :: String ( "hello" . to_string ( ) ) ,
1849+ & constraint,
1850+ ) ;
18421851 assert ! ( result. is_err( ) ) ;
18431852 assert ! ( result. unwrap_err( ) . contains( "expects Number" ) ) ;
18441853 }
18451854
18461855 #[ test]
18471856 fn test_string_enum_accepts_valid ( ) {
18481857 let constraint = ParamConstraint :: string_enum ( & [ "a" , "b" , "c" ] ) ;
1849- assert ! (
1850- validate_parameter( "test" , & ParameterValue :: String ( "a" . to_string( ) ) , & constraint)
1851- . is_ok( )
1852- ) ;
1858+ assert ! ( validate_parameter(
1859+ "test" ,
1860+ & ParameterValue :: String ( "a" . to_string( ) ) ,
1861+ & constraint
1862+ )
1863+ . is_ok( ) ) ;
18531864 }
18541865
18551866 #[ test]
18561867 fn test_string_enum_rejects_invalid ( ) {
18571868 let constraint = ParamConstraint :: string_enum ( & [ "a" , "b" , "c" ] ) ;
1858- let result =
1859- validate_parameter ( "test" , & ParameterValue :: String ( "d" . to_string ( ) ) , & constraint) ;
1869+ let result = validate_parameter (
1870+ "test" ,
1871+ & ParameterValue :: String ( "d" . to_string ( ) ) ,
1872+ & constraint,
1873+ ) ;
18601874 assert ! ( result. is_err( ) ) ;
18611875 assert ! ( result. unwrap_err( ) . contains( "Invalid value 'd'" ) ) ;
18621876 }
@@ -1873,14 +1887,19 @@ mod tests {
18731887 fn test_boolean_accepts_valid ( ) {
18741888 let constraint = ParamConstraint :: boolean ( ) ;
18751889 assert ! ( validate_parameter( "reverse" , & ParameterValue :: Boolean ( true ) , & constraint) . is_ok( ) ) ;
1876- assert ! ( validate_parameter( "reverse" , & ParameterValue :: Boolean ( false ) , & constraint) . is_ok( ) ) ;
1890+ assert ! (
1891+ validate_parameter( "reverse" , & ParameterValue :: Boolean ( false ) , & constraint) . is_ok( )
1892+ ) ;
18771893 }
18781894
18791895 #[ test]
18801896 fn test_boolean_rejects_wrong_type ( ) {
18811897 let constraint = ParamConstraint :: boolean ( ) ;
1882- let result =
1883- validate_parameter ( "reverse" , & ParameterValue :: String ( "true" . to_string ( ) ) , & constraint) ;
1898+ let result = validate_parameter (
1899+ "reverse" ,
1900+ & ParameterValue :: String ( "true" . to_string ( ) ) ,
1901+ & constraint,
1902+ ) ;
18841903 assert ! ( result. is_err( ) ) ;
18851904 assert ! ( result. unwrap_err( ) . contains( "expects Boolean" ) ) ;
18861905 }
@@ -1900,10 +1919,8 @@ mod tests {
19001919 NumberConstraint :: min ( 0.0 ) ,
19011920 ArrayConstraint :: of_numbers_len ( 2 , NumberConstraint :: min ( 0.0 ) ) ,
19021921 ) ;
1903- let arr = ParameterValue :: Array ( vec ! [
1904- ArrayElement :: Number ( 0.05 ) ,
1905- ArrayElement :: Number ( 10.0 ) ,
1906- ] ) ;
1922+ let arr =
1923+ ParameterValue :: Array ( vec ! [ ArrayElement :: Number ( 0.05 ) , ArrayElement :: Number ( 10.0 ) ] ) ;
19071924 assert ! ( validate_parameter( "expand" , & arr, & constraint) . is_ok( ) ) ;
19081925 }
19091926
@@ -1925,8 +1942,11 @@ mod tests {
19251942 NumberConstraint :: min ( 0.0 ) ,
19261943 ArrayConstraint :: of_numbers_len ( 2 , NumberConstraint :: min ( 0.0 ) ) ,
19271944 ) ;
1928- let result =
1929- validate_parameter ( "expand" , & ParameterValue :: String ( "0.05" . to_string ( ) ) , & constraint) ;
1945+ let result = validate_parameter (
1946+ "expand" ,
1947+ & ParameterValue :: String ( "0.05" . to_string ( ) ) ,
1948+ & constraint,
1949+ ) ;
19301950 assert ! ( result. is_err( ) ) ;
19311951 assert ! ( result. unwrap_err( ) . contains( "expects Number, Array" ) ) ;
19321952 }
@@ -1993,7 +2013,9 @@ mod tests {
19932013 ) ;
19942014 let result = validate_parameter ( "breaks" , & ParameterValue :: Boolean ( true ) , & constraint) ;
19952015 assert ! ( result. is_err( ) ) ;
1996- assert ! ( result. unwrap_err( ) . contains( "expects Number, String, Array" ) ) ;
2016+ assert ! ( result
2017+ . unwrap_err( )
2018+ . contains( "expects Number, String, Array" ) ) ;
19972019 }
19982020
19992021 #[ test]
@@ -2056,10 +2078,12 @@ mod tests {
20562078 #[ test]
20572079 fn test_string_or_string_array_accepts_string ( ) {
20582080 let constraint = ParamConstraint :: string_or_string_array ( & [ "x" , "y" ] ) ;
2059- assert ! (
2060- validate_parameter( "free" , & ParameterValue :: String ( "x" . to_string( ) ) , & constraint)
2061- . is_ok( )
2062- ) ;
2081+ assert ! ( validate_parameter(
2082+ "free" ,
2083+ & ParameterValue :: String ( "x" . to_string( ) ) ,
2084+ & constraint
2085+ )
2086+ . is_ok( ) ) ;
20632087 }
20642088
20652089 #[ test]
0 commit comments