mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-23 05:03:47 +00:00
Extract constant MARGIN out of Printer struct
This commit is contained in:
parent
24b8bb13bf
commit
67259e74a4
@ -199,10 +199,11 @@ enum PrintFrame {
|
|||||||
|
|
||||||
const SIZE_INFINITY: isize = 0xffff;
|
const SIZE_INFINITY: isize = 0xffff;
|
||||||
|
|
||||||
|
/// Target line width.
|
||||||
|
const MARGIN: isize = 78;
|
||||||
|
|
||||||
pub struct Printer {
|
pub struct Printer {
|
||||||
out: String,
|
out: String,
|
||||||
/// Width of lines we're constrained to
|
|
||||||
margin: isize,
|
|
||||||
/// Number of spaces left on line
|
/// Number of spaces left on line
|
||||||
space: isize,
|
space: isize,
|
||||||
/// Ring-buffer of tokens and calculated sizes
|
/// Ring-buffer of tokens and calculated sizes
|
||||||
@ -237,11 +238,9 @@ struct BufEntry {
|
|||||||
|
|
||||||
impl Printer {
|
impl Printer {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let linewidth = 78;
|
|
||||||
Printer {
|
Printer {
|
||||||
out: String::new(),
|
out: String::new(),
|
||||||
margin: linewidth as isize,
|
space: MARGIN,
|
||||||
space: linewidth as isize,
|
|
||||||
buf: RingBuffer::new(),
|
buf: RingBuffer::new(),
|
||||||
left_total: 0,
|
left_total: 0,
|
||||||
right_total: 0,
|
right_total: 0,
|
||||||
@ -395,7 +394,7 @@ impl Printer {
|
|||||||
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
|
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
|
||||||
self.indent = match token.indent {
|
self.indent = match token.indent {
|
||||||
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
|
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
|
||||||
IndentStyle::Visual => (self.margin - self.space) as usize,
|
IndentStyle::Visual => (MARGIN - self.space) as usize,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
self.print_stack.push(PrintFrame::Fits);
|
self.print_stack.push(PrintFrame::Fits);
|
||||||
@ -421,7 +420,7 @@ impl Printer {
|
|||||||
self.out.push('\n');
|
self.out.push('\n');
|
||||||
let indent = self.indent as isize + token.offset;
|
let indent = self.indent as isize + token.offset;
|
||||||
self.pending_indentation = indent;
|
self.pending_indentation = indent;
|
||||||
self.space = self.margin - indent;
|
self.space = MARGIN - indent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user