Factor out PairParts::infix

This commit is contained in:
Nick Cameron
2018-06-28 11:50:03 +12:00
parent fba6b68bf2
commit b6ea973d19
2 changed files with 16 additions and 5 deletions
+15 -4
View File
@@ -92,7 +92,7 @@ pub fn format_expr(
rewrite_pair(
&**lhs,
&**rhs,
PairParts::new("", &format!(" {} ", context.snippet(op.span)), ""),
PairParts::infix(&format!(" {} ", context.snippet(op.span))),
context,
shape,
context.config.binop_separator(),
@@ -211,7 +211,7 @@ pub fn format_expr(
ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair(
&**expr,
&**ty,
PairParts::new("", " as ", ""),
PairParts::infix(" as "),
context,
shape,
SeparatorPlace::Front,
@@ -219,7 +219,7 @@ pub fn format_expr(
ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair(
&**expr,
&**ty,
PairParts::new("", ": ", ""),
PairParts::infix(": "),
context,
shape,
SeparatorPlace::Back,
@@ -288,7 +288,7 @@ fn needs_space_after_range(rhs: &ast::Expr) -> bool {
rewrite_pair(
&*lhs,
&*rhs,
PairParts::new("", &sp_delim, ""),
PairParts::infix(&sp_delim),
context,
shape,
context.config.binop_separator(),
@@ -435,6 +435,7 @@ fn rewrite_simple_binaries(
None
}
/// Sigils that decorate a binop pair.
#[derive(new, Clone, Copy)]
pub struct PairParts<'a> {
prefix: &'a str,
@@ -442,6 +443,16 @@ pub struct PairParts<'a> {
suffix: &'a str,
}
impl<'a> PairParts<'a> {
pub fn infix(infix: &'a str) -> PairParts<'a> {
PairParts {
prefix: "",
infix,
suffix: "",
}
}
}
pub fn rewrite_pair<LHS, RHS>(
lhs: &LHS,
rhs: &RHS,
+1 -1
View File
@@ -112,7 +112,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
rewrite_pair(
&**lhs,
&**rhs,
PairParts::new("", &infix, ""),
PairParts::infix(&infix),
context,
shape,
SeparatorPlace::Front,