let item_fmt = ib.create_string_format(&fmt);
result.push_str(&comment_line_separator);
result.push_str(&ib.opener);
- match rewrite_string(&item_block_buffer.replace("\n", " "), &item_fmt) {
+ match rewrite_string(
+ &item_block_buffer.replace("\n", " "),
+ &item_fmt,
+ max_chars.saturating_sub(ib.indent),
+ ) {
Some(s) => result.push_str(&join_block(
&s,
&format!("{}{}", &comment_line_separator, ib.line_start),
}
if config.wrap_comments() && line.len() > fmt.shape.width && !has_url(line) {
- match rewrite_string(line, &fmt) {
+ match rewrite_string(line, &fmt, max_chars) {
Some(ref s) => {
is_prev_line_multi_line = s.contains('\n');
result.push_str(s);
result.pop();
result.push_str(&comment_line_separator);
fmt.shape = Shape::legacy(max_chars, fmt_indent);
- match rewrite_string(line, &fmt) {
+ match rewrite_string(line, &fmt, max_chars) {
Some(ref s) => {
is_prev_line_multi_line = s.contains('\n');
result.push_str(s);
let item_fmt = ib.create_string_format(&fmt);
result.push_str(&comment_line_separator);
result.push_str(&ib.opener);
- match rewrite_string(&item_block_buffer.replace("\n", " "), &item_fmt) {
+ match rewrite_string(
+ &item_block_buffer.replace("\n", " "),
+ &item_fmt,
+ max_chars.saturating_sub(ib.indent),
+ ) {
Some(s) => result.push_str(&join_block(
&s,
&format!("{}{}", &comment_line_separator, ib.line_start),
}
}
-pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String> {
+pub fn rewrite_string<'a>(
+ orig: &str,
+ fmt: &StringFormat<'a>,
+ newline_max_chars: usize,
+) -> Option<String> {
let max_chars_with_indent = fmt.max_chars_with_indent()?;
let max_chars_without_indent = fmt.max_chars_without_indent()?;
let indent_with_newline = fmt.shape.indent.to_string_with_newline(fmt.config);
result.push_str(fmt.line_end);
result.push_str(&indent_with_newline);
result.push_str(fmt.line_start);
- cur_max_chars = max_chars_with_indent;
+ cur_max_chars = newline_max_chars;
cur_start += len;
}
SnippetState::EndWithLineFeed(line, len) => {
fn issue343() {
let config = Default::default();
let fmt = StringFormat::new(Shape::legacy(2, Indent::empty()), &config);
- rewrite_string("eq_", &fmt);
+ rewrite_string("eq_", &fmt, 2);
}
#[test]
let mut config: Config = Default::default();
config.set().max_width(27);
let fmt = StringFormat::new(Shape::legacy(25, Indent::empty()), &config);
- let rewritten_string = rewrite_string(string, &fmt);
+ let rewritten_string = rewrite_string(string, &fmt, 27);
assert_eq!(
rewritten_string,
Some("\"Nulla\nconsequat erat at massa. \\\n Vivamus id mi.\"".to_string())
let mut fmt = StringFormat::new(Shape::legacy(25, Indent::empty()), &config);
fmt.trim_end = true;
- let rewritten_string = rewrite_string(string, &fmt);
+ let rewritten_string = rewrite_string(string, &fmt, 25);
assert_eq!(rewritten_string, Some("\"Vivamus id mi.\"".to_string()));
fmt.trim_end = false; // default value of trim_end
- let rewritten_string = rewrite_string(string, &fmt);
+ let rewritten_string = rewrite_string(string, &fmt, 25);
assert_eq!(rewritten_string, Some("\"Vivamus id mi. \"".to_string()));
}
config: &config,
};
- let rewritten_string = rewrite_string(string, &fmt);
+ let rewritten_string = rewrite_string(string, &fmt, 100);
assert_eq!(
rewritten_string,
Some("Vivamus id mi.\n // Vivamus id mi.".to_string())
};
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 30),
Some(
"Aenean metus.\n // Vestibulum ac lacus. Vivamus\n // porttitor"
.to_string()
};
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 30),
Some(
"Aenean metus.\n // Vestibulum ac lacus. Vivamus@\n // porttitor"
.to_string()
let comment = "Aenean metus. Vestibulum\n\nac lacus. Vivamus porttitor";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 30),
Some(
"Aenean metus. Vestibulum\n //\n // ac lacus. Vivamus porttitor".to_string()
)
fmt.shape = Shape::legacy(15, Indent::from_width(&config, 4));
let comment = "Aenean\n\nmetus. Vestibulum ac lacus. Vivamus porttitor";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 15),
Some(
r#"Aenean
//
let comment = "Aenean\n\nmetus. Vestibulum ac lacus.\n\n";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 20),
Some(
"Aenean\n //\n // metus. Vestibulum ac\n // lacus.\n //\n".to_string()
)
let comment = "Aenean\n\nmetus. Vestibulum ac lacus.\n";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 20),
Some("Aenean\n //\n // metus. Vestibulum ac\n // lacus.\n".to_string())
);
let comment = "Aenean\n \nmetus. Vestibulum ac lacus.";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 20),
Some("Aenean\n //\n // metus. Vestibulum ac\n // lacus.".to_string())
);
}
let comment = "Aenean metus. Vestibulum ac lacus.";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 13),
Some("Aenean metus.\n // Vestibulum ac\n // lacus.".to_string())
);
fmt.trim_end = false;
let comment = "Vestibulum ac lacus.";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 13),
Some("Vestibulum \n // ac lacus.".to_string())
);
fmt.line_end = "\\";
let comment = "Vestibulum ac lacus.";
assert_eq!(
- rewrite_string(comment, &fmt),
+ rewrite_string(comment, &fmt, 13),
Some("Vestibulum\\\n // ac lacus.".to_string())
);
}
/// All the parameters ***except for
/// `from_theater`*** should be inserted as sent
/// by the remote theater, ie. as passed to
-/// [`Theater::send`] on the remote
-/// actor:
+/// [`Theater::send`] on the remote actor:
/// * `from` is the sending (remote) [`ActorId`],
/// as reported by the remote theater by
/// theater-specific means
/// All the parameters ***except for
/// `from_theater`*** should be inserted as sent
/// by the remote theater, ie. as passed to
-/// [`Theater::send`] on the remote
-/// actor
+/// [`Theater::send`] on the remote actor
fn func1() {}
/// All the parameters ***except for
/// `from_theater`*** should be inserted as sent
/// by the remote theater, ie. as passed to
-/// [`Theater::send`] on the remote
-/// actor:
+/// [`Theater::send`] on the remote actor:
/// * `from` is the sending (remote) [`ActorId`],
/// as reported by the remote theater by
/// theater-specific means