From 1cb90f4e65cfdf61ddffc3bb8daf63b2647b0b25 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 21 Sep 2019 15:35:03 -0700 Subject: [PATCH] Use `pub(crate)` instead of `pub` (#471) Eventually, there will probably be a `crate` visibility specifier that does the same thing as `pub(crate)`. This commit replaces `pub` with `pub(crate)`, so when `crate` is available we can easily switch to it. --- src/alias.rs | 10 ++++----- src/alias_resolver.rs | 4 ++-- src/assignment_evaluator.rs | 28 ++++++++++++------------ src/assignment_resolver.rs | 4 ++-- src/color.rs | 40 +++++++++++++++++------------------ src/command_ext.rs | 2 +- src/common.rs | 4 ++-- src/compilation_error.rs | 14 ++++++------ src/compilation_error_kind.rs | 2 +- src/configuration.rs | 20 +++++++++--------- src/expression.rs | 6 +++--- src/fragment.rs | 4 ++-- src/function.rs | 18 ++++++++-------- src/function_context.rs | 6 +++--- src/functions.rs | 4 ++-- src/fuzzing.rs | 2 +- src/interrupt_guard.rs | 4 ++-- src/interrupt_handler.rs | 12 +++++------ src/justfile.rs | 24 ++++++++++----------- src/lexer.rs | 4 ++-- src/lib.rs | 2 +- src/load_dotenv.rs | 2 +- src/misc.rs | 20 +++++++++--------- src/ordinal.rs | 2 +- src/output.rs | 2 +- src/output_error.rs | 2 +- src/parameter.rs | 10 ++++----- src/parser.rs | 8 +++---- src/platform.rs | 2 +- src/platform_interface.rs | 2 +- src/position.rs | 8 +++---- src/range_ext.rs | 2 +- src/recipe.rs | 30 +++++++++++++------------- src/recipe_context.rs | 8 +++---- src/recipe_resolver.rs | 4 ++-- src/runtime_error.rs | 4 ++-- src/search.rs | 2 +- src/search_error.rs | 2 +- src/shebang.rs | 8 +++---- src/state.rs | 2 +- src/string_literal.rs | 8 +++---- src/testing.rs | 4 ++-- src/token.rs | 18 ++++++++-------- src/token_kind.rs | 2 +- src/use_color.rs | 2 +- src/variables.rs | 4 ++-- src/verbosity.rs | 8 +++---- 47 files changed, 190 insertions(+), 190 deletions(-) diff --git a/src/alias.rs b/src/alias.rs index b1ae10e..3e6a87a 100644 --- a/src/alias.rs +++ b/src/alias.rs @@ -1,11 +1,11 @@ use crate::common::*; #[derive(Debug)] -pub struct Alias<'a> { - pub name: &'a str, - pub target: &'a str, - pub line_number: usize, - pub private: bool, +pub(crate) struct Alias<'a> { + pub(crate) name: &'a str, + pub(crate) target: &'a str, + pub(crate) line_number: usize, + pub(crate) private: bool, } impl<'a> Display for Alias<'a> { diff --git a/src/alias_resolver.rs b/src/alias_resolver.rs index e8c85f9..d0c2fe9 100644 --- a/src/alias_resolver.rs +++ b/src/alias_resolver.rs @@ -1,7 +1,7 @@ use crate::common::*; use CompilationErrorKind::*; -pub struct AliasResolver<'a, 'b> +pub(crate) struct AliasResolver<'a, 'b> where 'a: 'b, { @@ -11,7 +11,7 @@ where } impl<'a: 'b, 'b> AliasResolver<'a, 'b> { - pub fn resolve_aliases( + pub(crate) fn resolve_aliases( aliases: &BTreeMap<&'a str, Alias<'a>>, recipes: &BTreeMap<&'a str, Recipe<'a>>, alias_tokens: &BTreeMap<&'a str, Token<'a>>, diff --git a/src/assignment_evaluator.rs b/src/assignment_evaluator.rs index 3d6662a..e038fc8 100644 --- a/src/assignment_evaluator.rs +++ b/src/assignment_evaluator.rs @@ -1,20 +1,20 @@ use crate::common::*; -pub struct AssignmentEvaluator<'a: 'b, 'b> { - pub assignments: &'b BTreeMap<&'a str, Expression<'a>>, - pub invocation_directory: &'b Result, - pub dotenv: &'b BTreeMap, - pub dry_run: bool, - pub evaluated: BTreeMap<&'a str, String>, - pub exports: &'b BTreeSet<&'a str>, - pub overrides: &'b BTreeMap<&'b str, &'b str>, - pub quiet: bool, - pub scope: &'b BTreeMap<&'a str, String>, - pub shell: &'b str, +pub(crate) struct AssignmentEvaluator<'a: 'b, 'b> { + pub(crate) assignments: &'b BTreeMap<&'a str, Expression<'a>>, + pub(crate) invocation_directory: &'b Result, + pub(crate) dotenv: &'b BTreeMap, + pub(crate) dry_run: bool, + pub(crate) evaluated: BTreeMap<&'a str, String>, + pub(crate) exports: &'b BTreeSet<&'a str>, + pub(crate) overrides: &'b BTreeMap<&'b str, &'b str>, + pub(crate) quiet: bool, + pub(crate) scope: &'b BTreeMap<&'a str, String>, + pub(crate) shell: &'b str, } impl<'a, 'b> AssignmentEvaluator<'a, 'b> { - pub fn evaluate_assignments( + pub(crate) fn evaluate_assignments( assignments: &BTreeMap<&'a str, Expression<'a>>, invocation_directory: &Result, dotenv: &'b BTreeMap, @@ -43,7 +43,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> { Ok(evaluator.evaluated) } - pub fn evaluate_line( + pub(crate) fn evaluate_line( &mut self, line: &[Fragment<'a>], arguments: &BTreeMap<&str, Cow>, @@ -81,7 +81,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> { Ok(()) } - pub fn evaluate_expression( + pub(crate) fn evaluate_expression( &mut self, expression: &Expression<'a>, arguments: &BTreeMap<&str, Cow>, diff --git a/src/assignment_resolver.rs b/src/assignment_resolver.rs index f37029b..3d015ce 100644 --- a/src/assignment_resolver.rs +++ b/src/assignment_resolver.rs @@ -2,7 +2,7 @@ use crate::common::*; use CompilationErrorKind::*; -pub struct AssignmentResolver<'a: 'b, 'b> { +pub(crate) struct AssignmentResolver<'a: 'b, 'b> { assignments: &'b BTreeMap<&'a str, Expression<'a>>, assignment_tokens: &'b BTreeMap<&'a str, Token<'a>>, stack: Vec<&'a str>, @@ -11,7 +11,7 @@ pub struct AssignmentResolver<'a: 'b, 'b> { } impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> { - pub fn resolve_assignments( + pub(crate) fn resolve_assignments( assignments: &BTreeMap<&'a str, Expression<'a>>, assignment_tokens: &BTreeMap<&'a str, Token<'a>>, ) -> CompilationResult<'a, ()> { diff --git a/src/color.rs b/src/color.rs index 196c483..95b7e6e 100644 --- a/src/color.rs +++ b/src/color.rs @@ -5,7 +5,7 @@ use ansi_term::{ANSIGenericString, Prefix, Style, Suffix}; use atty::Stream; #[derive(Copy, Clone)] -pub struct Color { +pub(crate) struct Color { use_color: UseColor, atty: bool, style: Style, @@ -31,7 +31,7 @@ impl Color { } } - pub fn fmt(fmt: &Formatter) -> Color { + pub(crate) fn fmt(fmt: &Formatter) -> Color { if fmt.alternate() { Color::always() } else { @@ -39,72 +39,72 @@ impl Color { } } - pub fn auto() -> Color { + pub(crate) fn auto() -> Color { Color { use_color: UseColor::Auto, ..default() } } - pub fn always() -> Color { + pub(crate) fn always() -> Color { Color { use_color: UseColor::Always, ..default() } } - pub fn never() -> Color { + pub(crate) fn never() -> Color { Color { use_color: UseColor::Never, ..default() } } - pub fn stderr(self) -> Color { + pub(crate) fn stderr(self) -> Color { self.redirect(Stream::Stderr) } - pub fn stdout(self) -> Color { + pub(crate) fn stdout(self) -> Color { self.redirect(Stream::Stdout) } - pub fn doc(self) -> Color { + pub(crate) fn doc(self) -> Color { self.restyle(Style::new().fg(Blue)) } - pub fn error(self) -> Color { + pub(crate) fn error(self) -> Color { self.restyle(Style::new().fg(Red).bold()) } - pub fn warning(self) -> Color { + pub(crate) fn warning(self) -> Color { self.restyle(Style::new().fg(Yellow).bold()) } - pub fn banner(self) -> Color { + pub(crate) fn banner(self) -> Color { self.restyle(Style::new().fg(Cyan).bold()) } - pub fn command(self) -> Color { + pub(crate) fn command(self) -> Color { self.restyle(Style::new().bold()) } - pub fn parameter(self) -> Color { + pub(crate) fn parameter(self) -> Color { self.restyle(Style::new().fg(Cyan)) } - pub fn message(self) -> Color { + pub(crate) fn message(self) -> Color { self.restyle(Style::new().bold()) } - pub fn annotation(self) -> Color { + pub(crate) fn annotation(self) -> Color { self.restyle(Style::new().fg(Purple)) } - pub fn string(self) -> Color { + pub(crate) fn string(self) -> Color { self.restyle(Style::new().fg(Green)) } - pub fn active(&self) -> bool { + pub(crate) fn active(&self) -> bool { match self.use_color { UseColor::Always => true, UseColor::Never => false, @@ -112,15 +112,15 @@ impl Color { } } - pub fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> { + pub(crate) fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> { self.effective_style().paint(text) } - pub fn prefix(&self) -> Prefix { + pub(crate) fn prefix(&self) -> Prefix { self.effective_style().prefix() } - pub fn suffix(&self) -> Suffix { + pub(crate) fn suffix(&self) -> Suffix { self.effective_style().suffix() } } diff --git a/src/command_ext.rs b/src/command_ext.rs index 2095c22..0d913ac 100644 --- a/src/command_ext.rs +++ b/src/command_ext.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub trait CommandExt { +pub(crate) trait CommandExt { fn export_environment_variables<'a>( &mut self, scope: &BTreeMap<&'a str, String>, diff --git a/src/common.rs b/src/common.rs index c807ce9..75abad8 100644 --- a/src/common.rs +++ b/src/common.rs @@ -49,9 +49,9 @@ pub(crate) use crate::{ verbosity::Verbosity, }; -pub type CompilationResult<'a, T> = Result>; +pub(crate) type CompilationResult<'a, T> = Result>; -pub type RunResult<'a, T> = Result>; +pub(crate) type RunResult<'a, T> = Result>; #[allow(unused_imports)] pub(crate) use std::io::prelude::*; diff --git a/src/compilation_error.rs b/src/compilation_error.rs index f02c912..40252b1 100644 --- a/src/compilation_error.rs +++ b/src/compilation_error.rs @@ -3,13 +3,13 @@ use crate::common::*; use crate::misc::{maybe_s, show_whitespace, write_error_context, Or}; #[derive(Debug, PartialEq)] -pub struct CompilationError<'a> { - pub text: &'a str, - pub offset: usize, - pub line: usize, - pub column: usize, - pub width: usize, - pub kind: CompilationErrorKind<'a>, +pub(crate) struct CompilationError<'a> { + pub(crate) text: &'a str, + pub(crate) offset: usize, + pub(crate) line: usize, + pub(crate) column: usize, + pub(crate) width: usize, + pub(crate) kind: CompilationErrorKind<'a>, } impl<'a> Display for CompilationError<'a> { diff --git a/src/compilation_error_kind.rs b/src/compilation_error_kind.rs index 4da7f0e..5a1b378 100644 --- a/src/compilation_error_kind.rs +++ b/src/compilation_error_kind.rs @@ -1,7 +1,7 @@ use crate::common::*; #[derive(Debug, PartialEq)] -pub enum CompilationErrorKind<'a> { +pub(crate) enum CompilationErrorKind<'a> { AliasShadowsRecipe { alias: &'a str, recipe_line: usize, diff --git a/src/configuration.rs b/src/configuration.rs index 03f4dd9..568d44b 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -1,16 +1,16 @@ use crate::common::*; -pub const DEFAULT_SHELL: &str = "sh"; +pub(crate) const DEFAULT_SHELL: &str = "sh"; -pub struct Configuration<'a> { - pub dry_run: bool, - pub evaluate: bool, - pub highlight: bool, - pub overrides: BTreeMap<&'a str, &'a str>, - pub quiet: bool, - pub shell: &'a str, - pub color: Color, - pub verbosity: Verbosity, +pub(crate) struct Configuration<'a> { + pub(crate) dry_run: bool, + pub(crate) evaluate: bool, + pub(crate) highlight: bool, + pub(crate) overrides: BTreeMap<&'a str, &'a str>, + pub(crate) quiet: bool, + pub(crate) shell: &'a str, + pub(crate) color: Color, + pub(crate) verbosity: Verbosity, } impl<'a> Default for Configuration<'a> { diff --git a/src/expression.rs b/src/expression.rs index 9fd42d7..d1ba9c5 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -1,7 +1,7 @@ use crate::common::*; #[derive(PartialEq, Debug)] -pub enum Expression<'a> { +pub(crate) enum Expression<'a> { Backtick { raw: &'a str, token: Token<'a>, @@ -28,11 +28,11 @@ pub enum Expression<'a> { } impl<'a> Expression<'a> { - pub fn variables(&'a self) -> Variables<'a> { + pub(crate) fn variables(&'a self) -> Variables<'a> { Variables::new(self) } - pub fn functions(&'a self) -> Functions<'a> { + pub(crate) fn functions(&'a self) -> Functions<'a> { Functions::new(self) } } diff --git a/src/fragment.rs b/src/fragment.rs index 5171331..fed215f 100644 --- a/src/fragment.rs +++ b/src/fragment.rs @@ -1,13 +1,13 @@ use crate::common::*; #[derive(PartialEq, Debug)] -pub enum Fragment<'a> { +pub(crate) enum Fragment<'a> { Text { text: Token<'a> }, Expression { expression: Expression<'a> }, } impl<'a> Fragment<'a> { - pub fn continuation(&self) -> bool { + pub(crate) fn continuation(&self) -> bool { match *self { Fragment::Text { ref text } => text.lexeme().ends_with('\\'), _ => false, diff --git a/src/function.rs b/src/function.rs index dd34250..dec01fe 100644 --- a/src/function.rs +++ b/src/function.rs @@ -18,7 +18,7 @@ lazy_static! { .collect(); } -pub enum Function { +pub(crate) enum Function { Nullary(fn(&FunctionContext) -> Result), Unary(fn(&FunctionContext, &str) -> Result), Binary(fn(&FunctionContext, &str, &str) -> Result), @@ -34,7 +34,7 @@ impl Function { } } - pub fn resolve<'a>(token: &Token<'a>, argc: usize) -> CompilationResult<'a, ()> { + pub(crate) fn resolve<'a>(token: &Token<'a>, argc: usize) -> CompilationResult<'a, ()> { let name = token.lexeme(); if let Some(function) = FUNCTIONS.get(&name) { use self::Function::*; @@ -55,7 +55,7 @@ impl Function { } } - pub fn evaluate<'a>( + pub(crate) fn evaluate<'a>( token: &Token<'a>, name: &'a str, context: &FunctionContext, @@ -94,25 +94,25 @@ impl Function { } } -pub fn arch(_context: &FunctionContext) -> Result { +pub(crate) fn arch(_context: &FunctionContext) -> Result { Ok(target::arch().to_string()) } -pub fn os(_context: &FunctionContext) -> Result { +pub(crate) fn os(_context: &FunctionContext) -> Result { Ok(target::os().to_string()) } -pub fn os_family(_context: &FunctionContext) -> Result { +pub(crate) fn os_family(_context: &FunctionContext) -> Result { Ok(target::os_family().to_string()) } -pub fn invocation_directory(context: &FunctionContext) -> Result { +pub(crate) fn invocation_directory(context: &FunctionContext) -> Result { context.invocation_directory.clone().and_then(|s| { Platform::to_shell_path(&s).map_err(|e| format!("Error getting shell path: {}", e)) }) } -pub fn env_var(context: &FunctionContext, key: &str) -> Result { +pub(crate) fn env_var(context: &FunctionContext, key: &str) -> Result { use std::env::VarError::*; if let Some(value) = context.dotenv.get(key) { @@ -129,7 +129,7 @@ pub fn env_var(context: &FunctionContext, key: &str) -> Result { } } -pub fn env_var_or_default( +pub(crate) fn env_var_or_default( context: &FunctionContext, key: &str, default: &str, diff --git a/src/function_context.rs b/src/function_context.rs index 688eecf..b7cb5ff 100644 --- a/src/function_context.rs +++ b/src/function_context.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub struct FunctionContext<'a> { - pub invocation_directory: &'a Result, - pub dotenv: &'a BTreeMap, +pub(crate) struct FunctionContext<'a> { + pub(crate) invocation_directory: &'a Result, + pub(crate) dotenv: &'a BTreeMap, } diff --git a/src/functions.rs b/src/functions.rs index a315437..209818f 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -1,11 +1,11 @@ use crate::common::*; -pub struct Functions<'a> { +pub(crate) struct Functions<'a> { stack: Vec<&'a Expression<'a>>, } impl<'a> Functions<'a> { - pub fn new(root: &'a Expression<'a>) -> Functions<'a> { + pub(crate) fn new(root: &'a Expression<'a>) -> Functions<'a> { Functions { stack: vec![root] } } } diff --git a/src/fuzzing.rs b/src/fuzzing.rs index 6dfe0f2..b4da7d2 100644 --- a/src/fuzzing.rs +++ b/src/fuzzing.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub fn compile(text: &str) { +pub(crate) fn compile(text: &str) { if let Err(error) = Parser::parse(text) { if let CompilationErrorKind::Internal { .. } = error.kind { panic!("{}", error) diff --git a/src/interrupt_guard.rs b/src/interrupt_guard.rs index 74df596..90be44e 100644 --- a/src/interrupt_guard.rs +++ b/src/interrupt_guard.rs @@ -1,9 +1,9 @@ use crate::common::*; -pub struct InterruptGuard; +pub(crate) struct InterruptGuard; impl InterruptGuard { - pub fn new() -> InterruptGuard { + pub(crate) fn new() -> InterruptGuard { InterruptHandler::instance().block(); InterruptGuard } diff --git a/src/interrupt_handler.rs b/src/interrupt_handler.rs index b69279c..c926724 100644 --- a/src/interrupt_handler.rs +++ b/src/interrupt_handler.rs @@ -1,16 +1,16 @@ use crate::common::*; -pub struct InterruptHandler { +pub(crate) struct InterruptHandler { blocks: u32, interrupted: bool, } impl InterruptHandler { - pub fn install() -> Result<(), ctrlc::Error> { + pub(crate) fn install() -> Result<(), ctrlc::Error> { ctrlc::set_handler(|| InterruptHandler::instance().interrupt()) } - pub fn instance() -> MutexGuard<'static, InterruptHandler> { + pub(crate) fn instance() -> MutexGuard<'static, InterruptHandler> { lazy_static! { static ref INSTANCE: Mutex = Mutex::new(InterruptHandler::new()); } @@ -47,11 +47,11 @@ impl InterruptHandler { process::exit(130); } - pub fn block(&mut self) { + pub(crate) fn block(&mut self) { self.blocks += 1; } - pub fn unblock(&mut self) { + pub(crate) fn unblock(&mut self) { if self.blocks == 0 { die!( "{}", @@ -69,7 +69,7 @@ impl InterruptHandler { } } - pub fn guard T>(function: F) -> T { + pub(crate) fn guard T>(function: F) -> T { let _guard = InterruptGuard::new(); function() } diff --git a/src/justfile.rs b/src/justfile.rs index 6bf733e..9a9dee5 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -1,16 +1,16 @@ use crate::common::*; #[derive(Debug)] -pub struct Justfile<'a> { - pub recipes: BTreeMap<&'a str, Recipe<'a>>, - pub assignments: BTreeMap<&'a str, Expression<'a>>, - pub exports: BTreeSet<&'a str>, - pub aliases: BTreeMap<&'a str, Alias<'a>>, - pub deprecated_equals: bool, +pub(crate) struct Justfile<'a> { + pub(crate) recipes: BTreeMap<&'a str, Recipe<'a>>, + pub(crate) assignments: BTreeMap<&'a str, Expression<'a>>, + pub(crate) exports: BTreeSet<&'a str>, + pub(crate) aliases: BTreeMap<&'a str, Alias<'a>>, + pub(crate) deprecated_equals: bool, } impl<'a> Justfile<'a> where { - pub fn first(&self) -> Option<&Recipe> { + pub(crate) fn first(&self) -> Option<&Recipe> { let mut first: Option<&Recipe> = None; for recipe in self.recipes.values() { if let Some(first_recipe) = first { @@ -24,11 +24,11 @@ impl<'a> Justfile<'a> where { first } - pub fn count(&self) -> usize { + pub(crate) fn count(&self) -> usize { self.recipes.len() } - pub fn suggest(&self, name: &str) -> Option<&'a str> { + pub(crate) fn suggest(&self, name: &str) -> Option<&'a str> { let mut suggestions = self .recipes .keys() @@ -43,7 +43,7 @@ impl<'a> Justfile<'a> where { None } - pub fn run( + pub(crate) fn run( &'a self, invocation_directory: &'a Result, arguments: &[&'a str], @@ -141,11 +141,11 @@ impl<'a> Justfile<'a> where { Ok(()) } - pub fn get_alias(&self, name: &str) -> Option<&Alias> { + pub(crate) fn get_alias(&self, name: &str) -> Option<&Alias> { self.aliases.get(name) } - pub fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> { + pub(crate) fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> { if let Some(recipe) = self.recipes.get(name) { Some(recipe) } else if let Some(alias) = self.aliases.get(name) { diff --git a/src/lexer.rs b/src/lexer.rs index f94cc49..8658b15 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -8,7 +8,7 @@ use TokenKind::*; /// `self.next` points to the next character to be lexed, and /// the text between `self.token_start` and `self.token_end` contains /// the current token being lexed. -pub struct Lexer<'a> { +pub(crate) struct Lexer<'a> { /// Source text text: &'a str, /// Char iterator @@ -27,7 +27,7 @@ pub struct Lexer<'a> { impl<'a> Lexer<'a> { /// Lex `text` - pub fn lex(text: &str) -> CompilationResult> { + pub(crate) fn lex(text: &str) -> CompilationResult> { Lexer::new(text).tokenize() } diff --git a/src/lib.rs b/src/lib.rs index 9e5abe5..7fd341c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ extern crate lazy_static; mod testing; #[cfg(fuzzing)] -pub mod fuzzing; +pub(crate) mod fuzzing; #[macro_use] mod die; diff --git a/src/load_dotenv.rs b/src/load_dotenv.rs index 8ebcad5..f0932fd 100644 --- a/src/load_dotenv.rs +++ b/src/load_dotenv.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub fn load_dotenv() -> RunResult<'static, BTreeMap> { +pub(crate) fn load_dotenv() -> RunResult<'static, BTreeMap> { match dotenv::dotenv_iter() { Ok(iter) => { let result: dotenv::Result> = iter.collect(); diff --git a/src/misc.rs b/src/misc.rs index 50f4efc..60ac529 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub fn show_whitespace(text: &str) -> String { +pub(crate) fn show_whitespace(text: &str) -> String { text .chars() .map(|c| match c { @@ -11,19 +11,19 @@ pub fn show_whitespace(text: &str) -> String { .collect() } -pub fn default() -> T { +pub(crate) fn default() -> T { Default::default() } -pub fn empty>() -> C { +pub(crate) fn empty>() -> C { iter::empty().collect() } -pub fn ticks(ts: &[T]) -> Vec> { +pub(crate) fn ticks(ts: &[T]) -> Vec> { ts.iter().map(Tick).collect() } -pub fn maybe_s(n: usize) -> &'static str { +pub(crate) fn maybe_s(n: usize) -> &'static str { if n == 1 { "" } else { @@ -31,7 +31,7 @@ pub fn maybe_s(n: usize) -> &'static str { } } -pub fn conjoin( +pub(crate) fn conjoin( f: &mut Formatter, values: &[T], conjunction: &str, @@ -55,7 +55,7 @@ pub fn conjoin( Ok(()) } -pub fn write_error_context( +pub(crate) fn write_error_context( f: &mut Formatter, text: &str, offset: usize, @@ -121,7 +121,7 @@ pub fn write_error_context( Ok(()) } -pub struct And<'a, T: 'a + Display>(pub &'a [T]); +pub(crate) struct And<'a, T: 'a + Display>(pub(crate) &'a [T]); impl<'a, T: Display> Display for And<'a, T> { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { @@ -129,7 +129,7 @@ impl<'a, T: Display> Display for And<'a, T> { } } -pub struct Or<'a, T: 'a + Display>(pub &'a [T]); +pub(crate) struct Or<'a, T: 'a + Display>(pub(crate) &'a [T]); impl<'a, T: Display> Display for Or<'a, T> { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { @@ -137,7 +137,7 @@ impl<'a, T: Display> Display for Or<'a, T> { } } -pub struct Tick<'a, T: 'a + Display>(pub &'a T); +pub(crate) struct Tick<'a, T: 'a + Display>(pub(crate) &'a T); impl<'a, T: Display> Display for Tick<'a, T> { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { diff --git a/src/ordinal.rs b/src/ordinal.rs index 7c53dbd..530af10 100644 --- a/src/ordinal.rs +++ b/src/ordinal.rs @@ -1,4 +1,4 @@ -pub trait Ordinal { +pub(crate) trait Ordinal { /// Convert an index starting at 0 to an ordinal starting at 1 fn ordinal(self) -> Self; } diff --git a/src/output.rs b/src/output.rs index 31e9340..1b828b3 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,7 +1,7 @@ use crate::common::*; /// Run a command and return the data it wrote to stdout as a string -pub fn output(mut command: Command) -> Result { +pub(crate) fn output(mut command: Command) -> Result { match command.output() { Ok(output) => { if let Some(code) = output.status.code() { diff --git a/src/output_error.rs b/src/output_error.rs index 9efc6e2..1f58f14 100644 --- a/src/output_error.rs +++ b/src/output_error.rs @@ -1,7 +1,7 @@ use crate::common::*; #[derive(Debug)] -pub enum OutputError { +pub(crate) enum OutputError { /// Non-zero exit code Code(i32), /// IO error diff --git a/src/parameter.rs b/src/parameter.rs index 9ff8980..c9d11d2 100644 --- a/src/parameter.rs +++ b/src/parameter.rs @@ -1,11 +1,11 @@ use crate::common::*; #[derive(PartialEq, Debug)] -pub struct Parameter<'a> { - pub default: Option>, - pub name: &'a str, - pub token: Token<'a>, - pub variadic: bool, +pub(crate) struct Parameter<'a> { + pub(crate) default: Option>, + pub(crate) name: &'a str, + pub(crate) token: Token<'a>, + pub(crate) variadic: bool, } impl<'a> Display for Parameter<'a> { diff --git a/src/parser.rs b/src/parser.rs index b45d5eb..eb1b5f8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3,7 +3,7 @@ use crate::common::*; use CompilationErrorKind::*; use TokenKind::*; -pub struct Parser<'a> { +pub(crate) struct Parser<'a> { text: &'a str, tokens: itertools::PutBackN>>, recipes: BTreeMap<&'a str, Recipe<'a>>, @@ -16,14 +16,14 @@ pub struct Parser<'a> { } impl<'a> Parser<'a> { - pub fn parse(text: &'a str) -> CompilationResult<'a, Justfile> { + pub(crate) fn parse(text: &'a str) -> CompilationResult<'a, Justfile> { let mut tokens = Lexer::lex(text)?; tokens.retain(|token| token.kind != Whitespace); let parser = Parser::new(text, tokens); parser.justfile() } - pub fn new(text: &'a str, tokens: Vec>) -> Parser<'a> { + pub(crate) fn new(text: &'a str, tokens: Vec>) -> Parser<'a> { Parser { tokens: itertools::put_back_n(tokens), recipes: empty(), @@ -391,7 +391,7 @@ impl<'a> Parser<'a> { Ok(()) } - pub fn justfile(mut self) -> CompilationResult<'a, Justfile<'a>> { + pub(crate) fn justfile(mut self) -> CompilationResult<'a, Justfile<'a>> { let mut doc = None; loop { match self.tokens.next() { diff --git a/src/platform.rs b/src/platform.rs index 762893f..f07f0ee 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub struct Platform; +pub(crate) struct Platform; #[cfg(unix)] impl PlatformInterface for Platform { diff --git a/src/platform_interface.rs b/src/platform_interface.rs index 151383a..2eb784c 100644 --- a/src/platform_interface.rs +++ b/src/platform_interface.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub trait PlatformInterface { +pub(crate) trait PlatformInterface { /// Construct a command equivalent to running the script at `path` with the /// shebang line `shebang` fn make_shebang_command( diff --git a/src/position.rs b/src/position.rs index caef3b7..face629 100644 --- a/src/position.rs +++ b/src/position.rs @@ -1,7 +1,7 @@ /// Source position #[derive(Copy, Clone, PartialEq, Debug)] -pub struct Position { - pub offset: usize, - pub column: usize, - pub line: usize, +pub(crate) struct Position { + pub(crate) offset: usize, + pub(crate) column: usize, + pub(crate) line: usize, } diff --git a/src/range_ext.rs b/src/range_ext.rs index 002c820..dd4296b 100644 --- a/src/range_ext.rs +++ b/src/range_ext.rs @@ -1,6 +1,6 @@ use crate::common::*; -pub trait RangeExt { +pub(crate) trait RangeExt { fn range_contains(&self, i: &T) -> bool; } diff --git a/src/recipe.rs b/src/recipe.rs index 92dcead..5245f2f 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -23,25 +23,25 @@ fn error_from_signal( } #[derive(PartialEq, Debug)] -pub struct Recipe<'a> { - pub dependencies: Vec<&'a str>, - pub dependency_tokens: Vec>, - pub doc: Option<&'a str>, - pub line_number: usize, - pub lines: Vec>>, - pub name: &'a str, - pub parameters: Vec>, - pub private: bool, - pub quiet: bool, - pub shebang: bool, +pub(crate) struct Recipe<'a> { + pub(crate) dependencies: Vec<&'a str>, + pub(crate) dependency_tokens: Vec>, + pub(crate) doc: Option<&'a str>, + pub(crate) line_number: usize, + pub(crate) lines: Vec>>, + pub(crate) name: &'a str, + pub(crate) parameters: Vec>, + pub(crate) private: bool, + pub(crate) quiet: bool, + pub(crate) shebang: bool, } impl<'a> Recipe<'a> { - pub fn argument_range(&self) -> RangeInclusive { + pub(crate) fn argument_range(&self) -> RangeInclusive { self.min_arguments()..=self.max_arguments() } - pub fn min_arguments(&self) -> usize { + pub(crate) fn min_arguments(&self) -> usize { self .parameters .iter() @@ -49,7 +49,7 @@ impl<'a> Recipe<'a> { .count() } - pub fn max_arguments(&self) -> usize { + pub(crate) fn max_arguments(&self) -> usize { if self.parameters.iter().any(|p| p.variadic) { usize::MAX - 1 } else { @@ -57,7 +57,7 @@ impl<'a> Recipe<'a> { } } - pub fn run( + pub(crate) fn run( &self, context: &RecipeContext<'a>, arguments: &[&'a str], diff --git a/src/recipe_context.rs b/src/recipe_context.rs index 59aaeb1..5777513 100644 --- a/src/recipe_context.rs +++ b/src/recipe_context.rs @@ -1,7 +1,7 @@ use crate::common::*; -pub struct RecipeContext<'a> { - pub invocation_directory: &'a Result, - pub configuration: &'a Configuration<'a>, - pub scope: BTreeMap<&'a str, String>, +pub(crate) struct RecipeContext<'a> { + pub(crate) invocation_directory: &'a Result, + pub(crate) configuration: &'a Configuration<'a>, + pub(crate) scope: BTreeMap<&'a str, String>, } diff --git a/src/recipe_resolver.rs b/src/recipe_resolver.rs index c540cc8..2619500 100644 --- a/src/recipe_resolver.rs +++ b/src/recipe_resolver.rs @@ -12,7 +12,7 @@ use CompilationErrorKind::*; // of the struct, and the second being the lifetime of the tokens // that it contains. -pub struct RecipeResolver<'a: 'b, 'b> { +pub(crate) struct RecipeResolver<'a: 'b, 'b> { stack: Vec<&'a str>, seen: BTreeSet<&'a str>, resolved: BTreeSet<&'a str>, @@ -22,7 +22,7 @@ pub struct RecipeResolver<'a: 'b, 'b> { } impl<'a, 'b> RecipeResolver<'a, 'b> { - pub fn resolve_recipes( + pub(crate) fn resolve_recipes( recipes: &BTreeMap<&'a str, Recipe<'a>>, assignments: &BTreeMap<&'a str, Expression<'a>>, text: &'a str, diff --git a/src/runtime_error.rs b/src/runtime_error.rs index 758e96e..1495cc7 100644 --- a/src/runtime_error.rs +++ b/src/runtime_error.rs @@ -3,7 +3,7 @@ use crate::common::*; use crate::misc::{maybe_s, ticks, write_error_context, And, Or, Tick}; #[derive(Debug)] -pub enum RuntimeError<'a> { +pub(crate) enum RuntimeError<'a> { ArgumentCountMismatch { recipe: &'a str, parameters: Vec<&'a Parameter<'a>>, @@ -67,7 +67,7 @@ pub enum RuntimeError<'a> { } impl<'a> RuntimeError<'a> { - pub fn code(&self) -> Option { + pub(crate) fn code(&self) -> Option { use RuntimeError::*; match *self { Code { code, .. } diff --git a/src/search.rs b/src/search.rs index e345fd5..be67eac 100644 --- a/src/search.rs +++ b/src/search.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; const FILENAME: &str = "justfile"; -pub fn justfile(directory: &Path) -> Result { +pub(crate) fn justfile(directory: &Path) -> Result { let mut candidates = Vec::new(); let dir = fs::read_dir(directory).map_err(|io_error| SearchError::Io { io_error, diff --git a/src/search_error.rs b/src/search_error.rs index ff82de7..dd226ec 100644 --- a/src/search_error.rs +++ b/src/search_error.rs @@ -2,7 +2,7 @@ use std::{fmt, io, path::PathBuf}; use crate::misc::And; -pub enum SearchError { +pub(crate) enum SearchError { MultipleCandidates { candidates: Vec, }, diff --git a/src/shebang.rs b/src/shebang.rs index 28a85d6..b6d4bdc 100644 --- a/src/shebang.rs +++ b/src/shebang.rs @@ -1,10 +1,10 @@ -pub struct Shebang<'a> { - pub interpreter: &'a str, - pub argument: Option<&'a str>, +pub(crate) struct Shebang<'a> { + pub(crate) interpreter: &'a str, + pub(crate) argument: Option<&'a str>, } impl<'a> Shebang<'a> { - pub fn new(text: &'a str) -> Option> { + pub(crate) fn new(text: &'a str) -> Option> { if !text.starts_with("#!") { return None; } diff --git a/src/state.rs b/src/state.rs index 37ffd6e..5ac4559 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,7 +1,7 @@ use crate::common::*; #[derive(Copy, Clone, PartialEq, Debug)] -pub enum State<'a> { +pub(crate) enum State<'a> { Normal, Indented { indentation: &'a str }, Text, diff --git a/src/string_literal.rs b/src/string_literal.rs index 11b4edb..d2de5bd 100644 --- a/src/string_literal.rs +++ b/src/string_literal.rs @@ -1,13 +1,13 @@ use crate::common::*; #[derive(PartialEq, Debug)] -pub struct StringLiteral<'a> { - pub raw: &'a str, - pub cooked: Cow<'a, str>, +pub(crate) struct StringLiteral<'a> { + pub(crate) raw: &'a str, + pub(crate) cooked: Cow<'a, str>, } impl<'a> StringLiteral<'a> { - pub fn new(token: &Token<'a>) -> CompilationResult<'a, StringLiteral<'a>> { + pub(crate) fn new(token: &Token<'a>) -> CompilationResult<'a, StringLiteral<'a>> { let raw = &token.lexeme()[1..token.lexeme().len() - 1]; if let TokenKind::StringRaw = token.kind { diff --git a/src/testing.rs b/src/testing.rs index 94165d3..be26103 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -1,13 +1,13 @@ use crate::common::*; -pub fn parse(text: &str) -> Justfile { +pub(crate) fn parse(text: &str) -> Justfile { match Parser::parse(text) { Ok(justfile) => justfile, Err(error) => panic!("Expected successful parse but got error:\n {}", error), } } -pub fn tempdir() -> tempfile::TempDir { +pub(crate) fn tempdir() -> tempfile::TempDir { tempfile::Builder::new() .prefix("just-test-tempdir") .tempdir() diff --git a/src/token.rs b/src/token.rs index fbb352c..2587153 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1,21 +1,21 @@ use crate::common::*; #[derive(Debug, PartialEq, Clone)] -pub struct Token<'a> { - pub offset: usize, - pub length: usize, - pub line: usize, - pub column: usize, - pub text: &'a str, - pub kind: TokenKind, +pub(crate) struct Token<'a> { + pub(crate) offset: usize, + pub(crate) length: usize, + pub(crate) line: usize, + pub(crate) column: usize, + pub(crate) text: &'a str, + pub(crate) kind: TokenKind, } impl<'a> Token<'a> { - pub fn lexeme(&self) -> &'a str { + pub(crate) fn lexeme(&self) -> &'a str { &self.text[self.offset..self.offset + self.length] } - pub fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> { + pub(crate) fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> { CompilationError { column: self.column, offset: self.offset, diff --git a/src/token_kind.rs b/src/token_kind.rs index 08e4f22..b74f4e2 100644 --- a/src/token_kind.rs +++ b/src/token_kind.rs @@ -1,7 +1,7 @@ use crate::common::*; #[derive(Debug, PartialEq, Clone, Copy)] -pub enum TokenKind { +pub(crate) enum TokenKind { At, Backtick, Colon, diff --git a/src/use_color.rs b/src/use_color.rs index 152b073..818e7fe 100644 --- a/src/use_color.rs +++ b/src/use_color.rs @@ -1,5 +1,5 @@ #[derive(Copy, Clone)] -pub enum UseColor { +pub(crate) enum UseColor { Auto, Always, Never, diff --git a/src/variables.rs b/src/variables.rs index 9c664c8..309bd1a 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -1,11 +1,11 @@ use crate::common::*; -pub struct Variables<'a> { +pub(crate) struct Variables<'a> { stack: Vec<&'a Expression<'a>>, } impl<'a> Variables<'a> { - pub fn new(root: &'a Expression<'a>) -> Variables<'a> { + pub(crate) fn new(root: &'a Expression<'a>) -> Variables<'a> { Variables { stack: vec![root] } } } diff --git a/src/verbosity.rs b/src/verbosity.rs index 5f2cab7..3025c04 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -1,14 +1,14 @@ use Verbosity::*; #[derive(Copy, Clone)] -pub enum Verbosity { +pub(crate) enum Verbosity { Taciturn, Loquacious, Grandiloquent, } impl Verbosity { - pub fn from_flag_occurrences(flag_occurences: u64) -> Verbosity { + pub(crate) fn from_flag_occurrences(flag_occurences: u64) -> Verbosity { match flag_occurences { 0 => Taciturn, 1 => Loquacious, @@ -16,7 +16,7 @@ impl Verbosity { } } - pub fn loquacious(self) -> bool { + pub(crate) fn loquacious(self) -> bool { match self { Taciturn => false, Loquacious => true, @@ -24,7 +24,7 @@ impl Verbosity { } } - pub fn grandiloquent(self) -> bool { + pub(crate) fn grandiloquent(self) -> bool { match self { Taciturn => false, Loquacious => false,