@@ -1241,35 +1241,72 @@ macro_rules! extensions_options {
1241
1241
Box :: new( self . clone( ) )
1242
1242
}
1243
1243
1244
- fn set( & mut self , key: & str , value: & str ) -> $crate:: Result <( ) > {
1245
- match key {
1246
- $(
1247
- stringify!( $field_name) => {
1248
- self . $field_name = value. parse( ) . map_err( |e| {
1249
- $crate:: DataFusionError :: Context (
1250
- format!( concat!( "Error parsing {} as " , stringify!( $t) , ) , value) ,
1251
- Box :: new( $crate:: DataFusionError :: External ( Box :: new( e) ) ) ,
1252
- )
1253
- } ) ?;
1254
- Ok ( ( ) )
1255
- }
1256
- ) *
1257
- _ => Err ( $crate:: DataFusionError :: Configuration (
1258
- format!( concat!( "Config value \" {}\" not found on " , stringify!( $struct_name) ) , key)
1259
- ) )
1260
- }
1244
+ fn set( & mut self , key: & str , value: & str ) -> $crate:: error:: Result <( ) > {
1245
+ $crate:: config:: ConfigField :: set( self , key, value)
1261
1246
}
1262
1247
1263
1248
fn entries( & self ) -> Vec <$crate:: config:: ConfigEntry > {
1264
- vec![
1249
+ struct Visitor ( Vec <$crate:: config:: ConfigEntry >) ;
1250
+
1251
+ impl $crate:: config:: Visit for Visitor {
1252
+ fn some<V : std:: fmt:: Display >(
1253
+ & mut self ,
1254
+ key: & str ,
1255
+ value: V ,
1256
+ description: & ' static str ,
1257
+ ) {
1258
+ self . 0 . push( $crate:: config:: ConfigEntry {
1259
+ key: key. to_string( ) ,
1260
+ value: Some ( value. to_string( ) ) ,
1261
+ description,
1262
+ } )
1263
+ }
1264
+
1265
+ fn none( & mut self , key: & str , description: & ' static str ) {
1266
+ self . 0 . push( $crate:: config:: ConfigEntry {
1267
+ key: key. to_string( ) ,
1268
+ value: None ,
1269
+ description,
1270
+ } )
1271
+ }
1272
+ }
1273
+
1274
+ let mut v = Visitor ( vec![ ] ) ;
1275
+ // The prefix is not used for extensions.
1276
+ // The description is generated in ConfigField::visit.
1277
+ // We can just pass empty strings here.
1278
+ $crate:: config:: ConfigField :: visit( self , & mut v, "" , "" ) ;
1279
+ v. 0
1280
+ }
1281
+ }
1282
+
1283
+ impl $crate:: config:: ConfigField for $struct_name {
1284
+ fn set( & mut self , key: & str , value: & str ) -> $crate:: error:: Result <( ) > {
1285
+ let ( key, rem) = key. split_once( '.' ) . unwrap_or( ( key, "" ) ) ;
1286
+ match key {
1265
1287
$(
1266
- $crate:: config:: ConfigEntry {
1267
- key: stringify!( $field_name) . to_owned( ) ,
1268
- value: ( self . $field_name != $default) . then( || self . $field_name. to_string( ) ) ,
1269
- description: concat!( $( $d) ,* ) . trim( ) ,
1288
+ stringify!( $field_name) => {
1289
+ // Safely apply deprecated attribute if present
1290
+ // $(#[allow(deprecated)])?
1291
+ {
1292
+ #[ allow( deprecated) ]
1293
+ self . $field_name. set( rem, value. as_ref( ) )
1294
+ }
1270
1295
} ,
1271
1296
) *
1272
- ]
1297
+ _ => return $crate:: error:: _config_err!(
1298
+ "Config value \" {}\" not found on {}" , key, stringify!( $struct_name)
1299
+ )
1300
+ }
1301
+ }
1302
+
1303
+ fn visit<V : $crate:: config:: Visit >( & self , v: & mut V , _key_prefix: & str , _description: & ' static str ) {
1304
+ $(
1305
+ let key = stringify!( $field_name) . to_string( ) ;
1306
+ let desc = concat!( $( $d) ,* ) . trim( ) ;
1307
+ #[ allow( deprecated) ]
1308
+ self . $field_name. visit( v, key. as_str( ) , desc) ;
1309
+ ) *
1273
1310
}
1274
1311
}
1275
1312
}
0 commit comments