Skip to content

Commit

Permalink
RFT: Simplify display function.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisvanrens committed Aug 10, 2023
1 parent b9ab22d commit b7ab558
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions nexus-rs/src/nxs_scanner/scan_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ pub struct ScanError {

impl Display for ScanError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// TODO: Simplify?
let prefix_fill = " ".repeat(
self.line
.number
.map_or("".to_owned(), |n| n.to_string())
.len()
+ 2,
); // +2 for spaces.
let line_number_str = self.line.number.map_or("".to_owned(), |n| n.to_string());
let prefix_fill = " ".repeat(line_number_str.len() + 2); // +2 for spaces.
let char_fill = " ".repeat(self.char_index);
f.write_fmt(format_args!(
"{}|\n {} | {}\n{}| {}{}\n{}| error: {}\n{}|",
prefix_fill,
self.line.number.map_or("".to_owned(), |n| n.to_string()),
line_number_str,
self.line.line,
prefix_fill,
char_fill,
Expand Down

0 comments on commit b7ab558

Please sign in to comment.