Skip to content

Commit

Permalink
Merge pull request #427 from tavianator/simplify-matcher-io
Browse files Browse the repository at this point in the history
Remove unnecessary lifetime parameter from Dependencies
  • Loading branch information
sylvestre authored Jul 28, 2024
2 parents c4a56e9 + 8771861 commit 5be00c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ use super::{Config, Dependencies};
pub struct MatcherIO<'a> {
should_skip_dir: bool,
quit: bool,
deps: &'a dyn Dependencies<'a>,
deps: &'a dyn Dependencies,
}

impl<'a> MatcherIO<'a> {
pub fn new(deps: &'a dyn Dependencies<'a>) -> MatcherIO<'a> {
pub fn new(deps: &dyn Dependencies) -> MatcherIO<'_> {
MatcherIO {
deps,
should_skip_dir: false,
Expand Down
26 changes: 13 additions & 13 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl Default for Config {

/// Trait that encapsulates various dependencies (output, clocks, etc.) that we
/// might want to fake out for unit tests.
pub trait Dependencies<'a> {
fn get_output(&'a self) -> &'a RefCell<dyn Write>;
fn now(&'a self) -> SystemTime;
pub trait Dependencies {
fn get_output(&self) -> &RefCell<dyn Write>;
fn now(&self) -> SystemTime;
}

/// Struct that holds the dependencies we use when run as the real executable.
Expand All @@ -73,12 +73,12 @@ impl Default for StandardDependencies {
}
}

impl<'a> Dependencies<'a> for StandardDependencies {
fn get_output(&'a self) -> &'a RefCell<dyn Write> {
impl Dependencies for StandardDependencies {
fn get_output(&self) -> &RefCell<dyn Write> {
self.output.as_ref()
}

fn now(&'a self) -> SystemTime {
fn now(&self) -> SystemTime {
self.now
}
}
Expand Down Expand Up @@ -135,10 +135,10 @@ fn parse_args(args: &[&str]) -> Result<ParsedInfo, Box<dyn Error>> {
})
}

fn process_dir<'a>(
fn process_dir(
dir: &str,
config: &Config,
deps: &'a dyn Dependencies<'a>,
deps: &dyn Dependencies,
matcher: &dyn matchers::Matcher,
quit: &mut bool,
) -> u64 {
Expand Down Expand Up @@ -180,7 +180,7 @@ fn process_dir<'a>(
found_count
}

fn do_find<'a>(args: &[&str], deps: &'a dyn Dependencies<'a>) -> Result<u64, Box<dyn Error>> {
fn do_find(args: &[&str], deps: &dyn Dependencies) -> Result<u64, Box<dyn Error>> {
let paths_and_matcher = parse_args(args)?;
if paths_and_matcher.config.help_requested {
print_help();
Expand Down Expand Up @@ -263,7 +263,7 @@ fn print_version() {
/// All main has to do is pass in the command-line args and exit the process
/// with the exit code. Note that the first string in args is expected to be
/// the name of the executable.
pub fn find_main<'a>(args: &[&str], deps: &'a dyn Dependencies<'a>) -> i32 {
pub fn find_main(args: &[&str], deps: &dyn Dependencies) -> i32 {
match do_find(&args[1..], deps) {
Ok(_) => uucore::error::get_exit_code(),
Err(e) => {
Expand Down Expand Up @@ -336,12 +336,12 @@ mod tests {
}
}

impl<'a> Dependencies<'a> for FakeDependencies {
fn get_output(&'a self) -> &'a RefCell<dyn Write> {
impl Dependencies for FakeDependencies {
fn get_output(&self) -> &RefCell<dyn Write> {
&self.output
}

fn now(&'a self) -> SystemTime {
fn now(&self) -> SystemTime {
self.now
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/common/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pub struct FakeDependencies {
now: SystemTime,
}

impl<'a> FakeDependencies {
impl FakeDependencies {
pub fn new() -> Self {
Self {
output: RefCell::new(Cursor::new(Vec::<u8>::new())),
now: SystemTime::now(),
}
}

pub fn new_matcher_io(&'a self) -> MatcherIO<'a> {
pub fn new_matcher_io(&self) -> MatcherIO<'_> {
MatcherIO::new(self)
}

Expand All @@ -42,12 +42,12 @@ impl<'a> FakeDependencies {
}
}

impl<'a> Dependencies<'a> for FakeDependencies {
fn get_output(&'a self) -> &'a RefCell<dyn Write> {
impl Dependencies for FakeDependencies {
fn get_output(&self) -> &RefCell<dyn Write> {
&self.output
}

fn now(&'a self) -> SystemTime {
fn now(&self) -> SystemTime {
self.now
}
}
Expand Down

0 comments on commit 5be00c8

Please sign in to comment.