Skip to content

Commit 88fecb7

Browse files
committed
Make the link target a field
1 parent 897d6ff commit 88fecb7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/output/file_name.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ use output::cell::TextCellContents;
1111
pub struct FileName<'a, 'dir: 'a> {
1212
file: &'a File<'dir>,
1313
colours: &'a Colours,
14+
target: Option<FileTarget<'dir>>,
1415
}
1516

1617
impl<'a, 'dir> FileName<'a, 'dir> {
1718
pub fn new(file: &'a File<'dir>, colours: &'a Colours) -> FileName<'a, 'dir> {
19+
let target = if file.is_link() { Some(file.link_target()) }
20+
else { None };
1821
FileName {
1922
file: file,
2023
colours: colours,
24+
target: target,
2125
}
2226
}
2327

@@ -36,9 +40,9 @@ impl<'a, 'dir> FileName<'a, 'dir> {
3640
}
3741
}
3842

39-
if links && self.file.is_link() {
40-
match self.file.link_target() {
41-
FileTarget::Ok(target) => {
43+
if links && self.target.is_some() {
44+
match self.target.as_ref().unwrap() {
45+
&FileTarget::Ok(ref target) => {
4246
bits.push(Style::default().paint(" "));
4347
bits.push(self.colours.punctuation.paint("->"));
4448
bits.push(Style::default().paint(" "));
@@ -55,16 +59,16 @@ impl<'a, 'dir> FileName<'a, 'dir> {
5559
}
5660
},
5761

58-
FileTarget::Broken(broken_path) => {
62+
&FileTarget::Broken(ref broken_path) => {
5963
bits.push(Style::default().paint(" "));
6064
bits.push(self.colours.broken_arrow.paint("->"));
6165
bits.push(Style::default().paint(" "));
6266
escape(broken_path.display().to_string(), &mut bits, self.colours.broken_filename, self.colours.control_char.underline());
6367
},
6468

65-
FileTarget::Err(_) => {
69+
&FileTarget::Err(_) => {
6670
// Do nothing -- the error gets displayed on the next line
67-
}
71+
},
6872
}
6973
}
7074
else if classify {

0 commit comments

Comments
 (0)