From 95b81e721297cf1dd481d744916ded04f91bebf0 Mon Sep 17 00:00:00 2001 From: zseri Date: Sat, 27 Mar 2021 08:16:56 +0100 Subject: omit args clone --- src/main.rs | 2 +- src/makefile/mod.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index e58188b..a78d9c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ fn main() { // TODO dump command-line args into MAKEFLAGS // TODO dump command-line macros into environment // TODO add SHELL macro - let mut makefile = Makefile::new(args.clone()); + let mut makefile = Makefile::new(&args); for filename in &args.makefile { if filename == &PathBuf::from("-") { makefile.and_read(stdin().lock()); diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index d55238e..dae742f 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -209,17 +209,17 @@ enum MacroSource { Builtin, } -pub struct Makefile { +pub struct Makefile<'a> { inference_rules: Vec, macros: HashMap, targets: RefCell>>>, pub first_non_special_target: Option, - args: Args, + args: &'a Args, // TODO borrow warnings from Python version } -impl Makefile { - pub fn new(args: Args) -> Makefile { +impl<'a> Makefile<'a> { + pub fn new(args: &'a Args) -> Self { let mut inference_rules = vec![]; let mut macros = HashMap::new(); let mut targets = HashMap::new(); @@ -264,7 +264,7 @@ impl Makefile { } } - pub fn and_read_file(&mut self, path: impl AsRef) -> &mut Makefile { + pub fn and_read_file(&mut self, path: impl AsRef) -> &mut Self { let file = File::open(path); // TODO handle errors let file = file.expect("couldn't open makefile!"); @@ -272,7 +272,7 @@ impl Makefile { self.and_read(file_reader) } - pub fn and_read(&mut self, source: impl BufRead) -> &mut Makefile { + pub fn and_read(&mut self, source: impl BufRead) -> &mut Self { let mut lines_iter = source.lines().enumerate().peekable(); while let Some((line_number, line)) = lines_iter.next() { // TODO handle I/O errors at all @@ -754,7 +754,7 @@ impl Makefile { } } -impl fmt::Display for Makefile { +impl fmt::Display for Makefile<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let header = |f: &mut fmt::Formatter, t: &str| { writeln!(f, "{}\n{:=^width$}", t, "", width = t.len()) -- cgit v1.2.3