on master help sign in
Update examples
commit13f671b49984ff68ca77e213429f00173b8a6755 authorsharkdp <davidpeter@web.de> dateWed 22 Apr 2020, 21:21 (7 years ago) parent49f4322
3 files changed+4−10
examples/advanced.rs+1−4 examples/simple.rs+1−4 src/pretty_printer.rs+2−2
examples/advanced.rs+1−4
@@ -1,10 +1,7 @@
11/// A program that prints its own source code using the bat library
22use bat::{LineRange, PrettyPrinter, WrappingMode};
3−use std::ffi::OsStr;
43
54fn main() {
6− let path_to_this_file = OsStr::new(file!());
7−
85 PrettyPrinter::new()
96 .header(true)
107 .grid(true)
@@ -14,7 +11,7 @@ fn main() {
1411 .highlight(LineRange::new(line!() as usize, line!() as usize))
1512 .theme("1337")
1613 .wrapping_mode(WrappingMode::Character)
17− .input_file(path_to_this_file)
14+ .input_file(file!())
1815 .print()
1916 .expect("no errors");
2017}
examples/simple.rs+1−4
@@ -1,12 +1,9 @@
11/// A simple program that prints its own source code using the bat library
22use bat::PrettyPrinter;
3−use std::ffi::OsStr;
43
54fn main() {
6− let path_to_this_file = OsStr::new(file!());
7−
85 PrettyPrinter::new()
9− .input_file(path_to_this_file)
6+ .input_file(file!())
107 .print()
118 .expect("no errors");
129}
src/pretty_printer.rs+2−2
@@ -55,8 +55,8 @@ impl<'a> PrettyPrinter<'a> {
5555 }
5656
5757 /// Add a file which should be pretty-printed
58− pub fn input_file(&mut self, path: &OsStr) -> &mut Self {
59− self.inputs.push(Input::ordinary_file(path));
58+ pub fn input_file(&mut self, path: impl AsRef<OsStr>) -> &mut Self {
59+ self.inputs.push(Input::ordinary_file(path.as_ref()));
6060 self
6161 }
6262