use comment::{FindUncommented, contains_comment};
use visitor::FmtVisitor;
use rewrite::{Rewrite, RewriteContext};
-use config::{Config, IndentStyle, Density, ReturnIndent, BraceStyle, Style};
+use config::{Config, IndentStyle, Density, ReturnIndent, BraceStyle, Style, TypeDensity};
use itertools::Itertools;
use syntax::{ast, abi, codemap, ptr, symbol};
let prefix = format!("type {}", ident);
let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
+ let joiner = match context.config.type_punctuation_density {
+ TypeDensity::Compressed => "+",
+ TypeDensity::Wide => " + ",
+ };
let bounds: &[_] = ty_param_bounds;
let bound_str = try_opt!(bounds
.iter()
.map(|ty_bound| {
ty_bound.rewrite(context, Shape::legacy(context.config.max_width, indent))
})
- .intersperse(Some(" + ".to_string()))
+ .intersperse(Some(joiner.to_string()))
.collect::<Option<String>>());
if bounds.len() > 0 {
format!(": {}", bound_str)
if bounds.is_empty() {
return Some(String::new());
}
-
+ let joiner = match context.config.type_punctuation_density {
+ TypeDensity::Compressed => "+",
+ TypeDensity::Wide => " + ",
+ };
let bound_str = try_opt!(bounds
.iter()
.map(|ty_bound| ty_bound.rewrite(&context, shape))
- .intersperse(Some(" + ".to_string()))
+ .intersperse(Some(joiner.to_string()))
.collect::<Option<String>>());
let mut result = String::new();
.intersperse(Some(", ".to_string()))
.collect());
+ let joiner = match context.config.type_punctuation_density {
+ TypeDensity::Compressed => "+",
+ TypeDensity::Wide => " + ",
+ };
// 6 = "for<> ".len()
let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
let budget = try_opt!(shape.width.checked_sub(used_width));
Shape::legacy(budget,
shape.indent + used_width))
})
- .intersperse(Some(" + ".to_string()))
+ .intersperse(Some(joiner.to_string()))
.collect());
if context.config.spaces_within_angle_brackets && lifetime_str.len() > 0 {
format!("for<{}> {}{}{}", lifetime_str, type_str, colon, bounds_str)
}
} else {
+ let joiner = match context.config.type_punctuation_density {
+ TypeDensity::Compressed => "+",
+ TypeDensity::Wide => " + ",
+ };
let used_width = type_str.len() + colon.len();
let budget = try_opt!(shape.width.checked_sub(used_width));
let bounds_str: String = try_opt!(bounds.iter()
Shape::legacy(budget,
shape.indent + used_width))
})
- .intersperse(Some(" + ".to_string()))
+ .intersperse(Some(joiner.to_string()))
.collect());
format!("{}{}{}", type_str, colon, bounds_str)
.map(|b| b.rewrite(context, shape))
.collect());
let colon = type_bound_colon(context);
- let result = format!("{}{}{}", result, colon, appendix.join(" + "));
+ let joiner = match context.config.type_punctuation_density {
+ TypeDensity::Compressed => "+",
+ TypeDensity::Wide => " + ",
+ };
+ let result = format!("{}{}{}", result, colon, appendix.join(joiner));
wrap_str(result, context.config.max_width, shape)
}
}
if context.config.space_after_bound_colon {
result.push_str(" ");
}
-
+ let joiner = match context.config.type_punctuation_density {
+ TypeDensity::Compressed => "+",
+ TypeDensity::Wide => " + ",
+ };
let bounds: String =
try_opt!(self.bounds
.iter()
.map(|ty_bound| ty_bound.rewrite(context, shape))
- .intersperse(Some(" + ".to_string()))
+ .intersperse(Some(joiner.to_string()))
.collect());
result.push_str(&bounds);