From 86c271eb2f9c0b3e1e2a35d26a2dca37435b5b8c Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 27 Mar 2021 17:02:11 -0600 Subject: why `pub` when you can `pub(crate)`? --- src/makefile/token.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/makefile/token.rs') 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); +pub(crate) struct TokenString(Vec); impl TokenString { - pub fn text(text: impl Into) -> Self { + pub(crate) fn text(text: impl Into) -> Self { Self(vec![Token::Text(text.into())]) } - pub fn tokens(&self) -> impl Iterator { + pub(crate) fn tokens(&self) -> impl Iterator { 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 -- cgit v1.2.3