aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzseri <zseri.devel@ytrizja.de>2021-03-27 08:16:56 +0100
committerzseri <zseri.devel@ytrizja.de>2021-03-27 08:16:56 +0100
commit95b81e721297cf1dd481d744916ded04f91bebf0 (patch)
tree5170575dc052ba30be92c1d93ff36845c8110730
parentf4c6afe3eb48088fed57fb9fcc4dce44bd505234 (diff)
downloadmakers-95b81e721297cf1dd481d744916ded04f91bebf0.tar.gz
makers-95b81e721297cf1dd481d744916ded04f91bebf0.zip
omit args clone
-rw-r--r--src/main.rs2
-rw-r--r--src/makefile/mod.rs14
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<InferenceRule>,
macros: HashMap<String, (MacroSource, TokenString)>,
targets: RefCell<HashMap<String, Rc<RefCell<Target>>>>,
pub first_non_special_target: Option<String>,
- 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<Path>) -> &mut Makefile {
+ pub fn and_read_file(&mut self, path: impl AsRef<Path>) -> &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())