@@ -423,6 +423,63 @@ macro_rules! create_config {
423423 ) +
424424 }
425425
426+ /// Reduces the maximum width of the configuration.
427+ ///
428+ /// This method is intended to be used when creating a forked
429+ /// configuration for a particular formatting context in which the
430+ /// total available width needs to be reduced. This reduces the
431+ /// size of max_width, and all other properties affected by small
432+ /// heuristics, without treating those adjustments as overrides.
433+ ///
434+ /// As an example use case, this method is used when formatting
435+ /// arms within a declarative macro.
436+ #[ allow( unreachable_pub) ]
437+ pub fn reduce_max_width( & mut self , delta: usize ) {
438+ self . adjust_max_width( -1 * delta as isize ) ;
439+ }
440+
441+ /// Increases the maximum width of the configuration.
442+ ///
443+ /// This method is intended to be used when creating a forked
444+ /// configuration for a particular formatting context in which the
445+ /// total available width needs to be reduced. This reduces the
446+ /// size of max_width, and all other properties affected by small
447+ /// heuristics, without treating those adjustments as overrides.
448+ ///
449+ /// As an example use case, this method is used when formatting
450+ /// arms within a declarative macro.
451+ #[ allow( unreachable_pub) ]
452+ pub fn increase_max_width( & mut self , delta: usize ) {
453+ self . adjust_max_width( delta as isize ) ;
454+ }
455+
456+ /// Adjusts the maximum width of the configuration.
457+ ///
458+ /// This method is intended to be used when creating a forked
459+ /// configuration for a particular formatting context in which the
460+ /// total available width needs to be reduced. This reduces the
461+ /// size of max_width, and all other properties affected by small
462+ /// heuristics, without treating those adjustments as overrides.
463+ ///
464+ /// As an example use case, this method is used when formatting
465+ /// arms within a declarative macro.
466+ fn adjust_max_width( & mut self , delta: isize ) {
467+ let adjust = |value: usize | ( value as isize + delta) as usize ;
468+
469+ self . array_width. 2 = adjust( self . array_width. 2 ) ;
470+ self . attr_fn_like_width. 2 = adjust( self . attr_fn_like_width. 2 ) ;
471+ self . chain_width. 2 = adjust( self . chain_width. 2 ) ;
472+ self . fn_call_width. 2 = adjust( self . fn_call_width. 2 ) ;
473+ self . single_line_if_else_max_width. 2 = adjust( self . single_line_if_else_max_width. 2 ) ;
474+ self . single_line_let_else_max_width. 2 =
475+ adjust( self . single_line_let_else_max_width. 2 ) ;
476+ self . struct_lit_width. 2 = adjust( self . struct_lit_width. 2 ) ;
477+ self . struct_variant_width. 2 = adjust( self . struct_variant_width. 2 ) ;
478+
479+ self . max_width. 2 = adjust( self . max_width. 2 ) ;
480+ self . set_heuristics( ) ;
481+ }
482+
426483 fn set_width_heuristics( & mut self , heuristics: WidthHeuristics ) {
427484 let max_width = self . max_width. 2 ;
428485 let get_width_value = |
0 commit comments