diff options
author | Melody Horn <melody@boringcactus.com> | 2021-03-27 17:02:11 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-03-27 17:02:11 -0600 |
commit | 86c271eb2f9c0b3e1e2a35d26a2dca37435b5b8c (patch) | |
tree | 5adc564056cf349793f4b9ffd6c70bf908117cc1 /src/makefile | |
parent | 5197d769bb2fea50975122a4ebba89c07c712839 (diff) | |
download | makers-86c271eb2f9c0b3e1e2a35d26a2dca37435b5b8c.tar.gz makers-86c271eb2f9c0b3e1e2a35d26a2dca37435b5b8c.zip |
why `pub` when you can `pub(crate)`?
Diffstat (limited to 'src/makefile')
-rw-r--r-- | src/makefile/command_line.rs | 6 | ||||
-rw-r--r-- | src/makefile/inference_rules.rs | 8 | ||||
-rw-r--r-- | src/makefile/mod.rs | 14 | ||||
-rw-r--r-- | src/makefile/target.rs | 14 | ||||
-rw-r--r-- | src/makefile/token.rs | 22 |
5 files changed, 32 insertions, 32 deletions
diff --git a/src/makefile/command_line.rs b/src/makefile/command_line.rs index 9cc0b8e..6b42105 100644 --- a/src/makefile/command_line.rs +++ b/src/makefile/command_line.rs @@ -26,7 +26,7 @@ fn execute_command_line(command_line: &str, ignore_errors: bool) -> Result<ExitS } #[derive(PartialEq, Eq, Clone, Debug)] -pub struct CommandLine { +pub(crate) struct CommandLine { /// If the command prefix contains a <hyphen-minus>, or the -i option is present, or /// the special target .IGNORE has either the current target as a prerequisite or has /// no prerequisites, any error found while executing the command shall be ignored. @@ -43,7 +43,7 @@ pub struct CommandLine { } impl CommandLine { - pub fn from(mut line: TokenString) -> Self { + pub(crate) fn from(mut line: TokenString) -> Self { let mut ignore_errors = false; let mut silent = false; let mut always_execute = false; @@ -69,7 +69,7 @@ impl CommandLine { } } - pub fn execute(&self, file: &Makefile, target: &Target) { + pub(crate) fn execute(&self, file: &Makefile, target: &Target) { let ignore_error = self.ignore_errors || file.args.ignore_errors || file.special_target_has_prereq(".IGNORE", &target.name); diff --git a/src/makefile/inference_rules.rs b/src/makefile/inference_rules.rs index 3d18730..397008b 100644 --- a/src/makefile/inference_rules.rs +++ b/src/makefile/inference_rules.rs @@ -3,12 +3,12 @@ use std::fmt; use crate::makefile::command_line::CommandLine; #[derive(PartialEq, Eq, Clone, Debug)] -pub struct InferenceRule { +pub(crate) struct InferenceRule { /// POSIX calls this ".s1" but that's not useful. - pub product: String, + pub(crate) product: String, /// POSIX calls this ".s2" but that's not useful. - pub prereq: String, - pub commands: Vec<CommandLine>, + pub(crate) prereq: String, + pub(crate) commands: Vec<CommandLine>, } impl fmt::Display for InferenceRule { diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index 1ce335d..23243e4 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -29,17 +29,17 @@ enum MacroSource { Builtin, } -pub struct Makefile<'a> { +pub(crate) 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>, + pub(crate) first_non_special_target: Option<String>, args: &'a Args, // TODO borrow warnings from Python version } impl<'a> Makefile<'a> { - pub fn new(args: &'a Args) -> Self { + pub(crate) fn new(args: &'a Args) -> Self { let mut inference_rules = vec![]; let mut macros = HashMap::new(); let mut targets = HashMap::new(); @@ -84,7 +84,7 @@ impl<'a> Makefile<'a> { } } - pub fn and_read_file(&mut self, path: impl AsRef<Path>) { + pub(crate) fn and_read_file(&mut self, path: impl AsRef<Path>) { let file = File::open(path); // TODO handle errors let file = file.expect("couldn't open makefile!"); @@ -92,7 +92,7 @@ impl<'a> Makefile<'a> { self.and_read(file_reader); } - pub fn and_read(&mut self, source: impl BufRead) { + pub(crate) fn and_read(&mut self, source: impl BufRead) { let mut lines_iter = source.lines().enumerate().peekable(); while let Some((line_number, line)) = lines_iter.next() { // TODO handle I/O errors at all @@ -369,7 +369,7 @@ impl<'a> Makefile<'a> { } } - pub fn get_target(&self, name: &str) -> Rc<RefCell<Target>> { + pub(crate) fn get_target(&self, name: &str) -> Rc<RefCell<Target>> { // TODO implement .POSIX let follow_gnu = true; @@ -467,7 +467,7 @@ impl<'a> Makefile<'a> { targets.get(name).expect("Target not found!").clone() } - pub fn update_target(&self, name: &str) { + pub(crate) fn update_target(&self, name: &str) { self.get_target(name).borrow().update(self); } diff --git a/src/makefile/target.rs b/src/makefile/target.rs index 1fbc75b..443eee5 100644 --- a/src/makefile/target.rs +++ b/src/makefile/target.rs @@ -8,11 +8,11 @@ use crate::makefile::command_line::CommandLine; use super::Makefile; #[derive(PartialEq, Eq, Clone, Debug)] -pub struct Target { - pub name: String, - pub prerequisites: Vec<String>, - pub commands: Vec<CommandLine>, - pub already_updated: Cell<bool>, +pub(crate) struct Target { + pub(crate) name: String, + pub(crate) prerequisites: Vec<String>, + pub(crate) commands: Vec<CommandLine>, + pub(crate) already_updated: Cell<bool>, } impl Target { @@ -22,7 +22,7 @@ impl Target { .ok() } - pub fn newer_than(&self, other: &Target) -> Option<bool> { + pub(crate) fn newer_than(&self, other: &Target) -> Option<bool> { let self_updated = self.already_updated.get(); let other_updated = other.already_updated.get(); Some(match (self.modified_time(), other.modified_time()) { @@ -48,7 +48,7 @@ impl Target { exists && newer_than_all_dependencies } - pub fn update(&self, file: &Makefile) { + pub(crate) fn update(&self, file: &Makefile) { for prereq in &self.prerequisites { file.update_target(prereq); } diff --git a/src/makefile/token.rs b/src/makefile/token.rs index 720055f..4fde3e5 100644 --- a/src/makefile/token.rs +++ b/src/makefile/token.rs @@ -12,22 +12,22 @@ use nom::{ }; #[derive(PartialEq, Eq, Clone, Debug)] -pub struct TokenString(Vec<Token>); +pub(crate) struct TokenString(Vec<Token>); impl TokenString { - pub fn text(text: impl Into<String>) -> Self { + pub(crate) fn text(text: impl Into<String>) -> Self { Self(vec![Token::Text(text.into())]) } - pub fn tokens(&self) -> impl Iterator<Item = &Token> { + pub(crate) fn tokens(&self) -> impl Iterator<Item = &Token> { self.0.iter() } - pub fn first_token_mut(&mut self) -> &mut Token { + pub(crate) fn first_token_mut(&mut self) -> &mut Token { &mut self.0[0] } - pub fn split_once(&self, delimiter: char) -> Option<(TokenString, TokenString)> { + pub(crate) fn split_once(&self, delimiter: char) -> Option<(TokenString, TokenString)> { let mut result0 = vec![]; let mut iter = self.0.iter(); while let Some(t) = iter.next() { @@ -47,14 +47,14 @@ impl TokenString { None } - pub fn ends_with(&self, pattern: &str) -> bool { + pub(crate) fn ends_with(&self, pattern: &str) -> bool { match self.0.last() { Some(Token::Text(t)) => t.ends_with(pattern), _ => false, } } - pub fn strip_suffix(&mut self, suffix: &str) { + pub(crate) fn strip_suffix(&mut self, suffix: &str) { if let Some(Token::Text(t)) = self.0.last_mut() { if let Some(x) = t.strip_suffix(suffix) { *t = x.into() @@ -62,11 +62,11 @@ impl TokenString { } } - pub fn extend(&mut self, other: TokenString) { + pub(crate) fn extend(&mut self, other: TokenString) { self.0.extend(other.0); } - pub fn trim_start(&mut self) { + pub(crate) fn trim_start(&mut self) { if let Some(Token::Text(t)) = self.0.first_mut() { *t = t.trim_start().into(); } @@ -83,7 +83,7 @@ impl fmt::Display for TokenString { } #[derive(PartialEq, Eq, Clone, Debug)] -pub enum Token { +pub(crate) enum Token { Text(String), MacroExpansion { name: String, @@ -192,7 +192,7 @@ fn full_text_tokens(input: &str) -> IResult<&str, TokenString> { all_consuming(tokens)(input) } -pub fn tokenize(input: &str) -> TokenString { +pub(crate) fn tokenize(input: &str) -> TokenString { // TODO handle errors gracefully let (_, result) = full_text_tokens(input).expect("couldn't parse"); result |