55//! both strings and lists), this module provides unified dispatch functions
66//! that route to the correct implementation based on the runtime type of `this`.
77
8- #[ cfg( any( feature = "ip" , feature = "lists" ) ) ]
9- use std:: sync:: Arc ;
8+ #[ cfg( any( feature = "ip" , feature = "lists" ) ) ] use std:: sync:: Arc ;
109
11- use cel:: extractors:: { Arguments , This } ;
12- use cel:: objects:: Value ;
13- use cel:: { Context , ExecutionError , ResolveResult } ;
10+ use cel:: {
11+ Context , ExecutionError , ResolveResult ,
12+ extractors:: { Arguments , This } ,
13+ objects:: Value ,
14+ } ;
1415
1516/// Register dispatch functions for names shared across multiple types or
1617/// that override cel built-in functions. Registration order is independent
@@ -158,11 +159,8 @@ fn ip_dispatch(This(this): This<Value>, Arguments(args): Arguments) -> ResolveRe
158159 }
159160 } ,
160161 } ;
161- let addr = crate :: ip:: parse_ip_addr ( & s)
162- . map_err ( |e| ExecutionError :: function_error ( "ip" , e) ) ?;
163- Ok ( Value :: Opaque ( std:: sync:: Arc :: new ( crate :: ip:: KubeIP :: new (
164- addr,
165- ) ) ) )
162+ let addr = crate :: ip:: parse_ip_addr ( & s) . map_err ( |e| ExecutionError :: function_error ( "ip" , e) ) ?;
163+ Ok ( Value :: Opaque ( std:: sync:: Arc :: new ( crate :: ip:: KubeIP :: new ( addr) ) ) )
166164 }
167165 }
168166}
@@ -209,8 +207,7 @@ fn builtin_string_fallback(this: Value) -> ResolveResult {
209207 ) ) ) ,
210208 Value :: Timestamp ( ref t) => Ok ( Value :: String ( Arc :: new ( t. to_rfc3339 ( ) ) ) ) ,
211209 Value :: Duration ( ref d) => Ok ( Value :: String ( Arc :: new ( format_cel_duration (
212- d. num_nanoseconds ( )
213- . unwrap_or ( d. num_seconds ( ) * 1_000_000_000 ) ,
210+ d. num_nanoseconds ( ) . unwrap_or ( d. num_seconds ( ) * 1_000_000_000 ) ,
214211 ) ) ) ) ,
215212 _ => Err ( ExecutionError :: function_error (
216213 "string" ,
@@ -391,10 +388,7 @@ mod tests {
391388 #[ test]
392389 #[ cfg( feature = "ip" ) ]
393390 fn test_string_float ( ) {
394- assert_eq ! (
395- eval( "3.14.string()" ) ,
396- Value :: String ( "3.14" . to_string( ) . into( ) )
397- ) ;
391+ assert_eq ! ( eval( "3.14.string()" ) , Value :: String ( "3.14" . to_string( ) . into( ) ) ) ;
398392 }
399393
400394 #[ test]
@@ -409,10 +403,7 @@ mod tests {
409403 #[ test]
410404 #[ cfg( feature = "ip" ) ]
411405 fn test_string_bytes ( ) {
412- assert_eq ! (
413- eval( "b'abc'.string()" ) ,
414- Value :: String ( "abc" . to_string( ) . into( ) )
415- ) ;
406+ assert_eq ! ( eval( "b'abc'.string()" ) , Value :: String ( "abc" . to_string( ) . into( ) ) ) ;
416407 }
417408
418409 #[ test]
0 commit comments