Reduce code duplication for block indentation helpers
This commit is contained in:
parent
c8fd23ca68
commit
e0ae162ae1
1 changed files with 12 additions and 14 deletions
26
src/expr.rs
26
src/expr.rs
|
@ -762,22 +762,20 @@ fn rewrite_call(context: &RewriteContext,
|
||||||
Some(format!("{}({})", callee_str, write_list(&items.collect::<Vec<_>>(), &fmt)))
|
Some(format!("{}({})", callee_str, write_list(&items.collect::<Vec<_>>(), &fmt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_block_indent(context: &RewriteContext, offset: usize) -> usize {
|
macro_rules! block_indent_helper {
|
||||||
match context.config.expr_indent_style {
|
($name:ident, $option:ident) => (
|
||||||
BlockIndentStyle::Inherit => context.block_indent,
|
fn $name(context: &RewriteContext, offset: usize) -> usize {
|
||||||
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
match context.config.$option {
|
||||||
BlockIndentStyle::Visual => offset,
|
BlockIndentStyle::Inherit => context.block_indent,
|
||||||
}
|
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
||||||
|
BlockIndentStyle::Visual => offset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Code duplication; is there a better solution?
|
block_indent_helper!(expr_block_indent, expr_indent_style);
|
||||||
fn closure_block_indent(context: &RewriteContext, offset: usize) -> usize {
|
block_indent_helper!(closure_block_indent, closure_indent_style);
|
||||||
match context.config.closure_indent_style {
|
|
||||||
BlockIndentStyle::Inherit => context.block_indent,
|
|
||||||
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
|
||||||
BlockIndentStyle::Visual => offset,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rewrite_paren(context: &RewriteContext,
|
fn rewrite_paren(context: &RewriteContext,
|
||||||
subexpr: &ast::Expr,
|
subexpr: &ast::Expr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue