Skip to content

Commit

Permalink
Remove unnecessary uses of vector of files (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro committed Apr 15, 2021
1 parent d5d939b commit ab7289e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/actor.rs
Expand Up @@ -115,9 +115,9 @@ NAVIEOF
opts.suggestion_type = SuggestionType::Disabled;
};

let (output, _) = config
let (output, _, _) = config
.finder
.call(opts, &mut Vec::new(), |stdin, _| {
.call(opts, |stdin, _| {
stdin
.write_all(suggestions.as_bytes())
.context("Could not write to finder's stdin")?;
Expand Down Expand Up @@ -178,7 +178,7 @@ fn replace_variables_from_snippet(
pub fn act(
extractions: Result<extractor::Output, Error>,
config: Config,
files: &mut Vec<String>,
files: Vec<String>,
variables: Option<VariableMap>,
) -> Result<(), Error> {
let (key, tags, comment, snippet, file_index) = extractions.unwrap();
Expand Down
8 changes: 3 additions & 5 deletions src/cmds/core.rs
Expand Up @@ -46,11 +46,9 @@ fn gen_core_finder_opts(config: &Config) -> Result<FinderOpts, Error> {
pub fn main(config: Config) -> Result<(), Error> {
let opts = gen_core_finder_opts(&config).context("Failed to generate finder options")?;

let mut files = Vec::new();

let (raw_selection, variables) = config
let (raw_selection, variables, files) = config
.finder
.call(opts, &mut files, |stdin, files| {
.call(opts, |stdin, files| {
let mut writer = writer::terminal::Writer::new();

let fetcher: Box<dyn Fetcher> = match config.source() {
Expand Down Expand Up @@ -78,7 +76,7 @@ pub fn main(config: Config) -> Result<(), Error> {
return main(config);
}

actor::act(extractions, config, &mut files, variables)?;
actor::act(extractions, config, files, variables)?;

Ok(())
}
12 changes: 6 additions & 6 deletions src/cmds/repo.rs
Expand Up @@ -39,8 +39,8 @@ pub fn browse(finder: &FinderChoice) -> Result<(), Error> {
..Default::default()
};

let (repo, _) = finder
.call(opts, &mut Vec::new(), |stdin, _| {
let (repo, _, _) = finder
.call(opts, |stdin, _| {
stdin
.write_all(repos.as_bytes())
.context("Unable to prompt featured repositories")?;
Expand All @@ -60,8 +60,8 @@ pub fn ask_if_should_import_all(finder: &FinderChoice) -> Result<bool, Error> {
..Default::default()
};

let (response, _) = finder
.call(opts, &mut Vec::new(), |stdin, _| {
let (response, _, _) = finder
.call(opts, |stdin, _| {
stdin
.write_all(b"Yes\nNo")
.context("Unable to writer alternatives")?;
Expand Down Expand Up @@ -105,8 +105,8 @@ pub fn add(uri: String, finder: &FinderChoice) -> Result<(), Error> {
let files = if should_import_all {
all_files
} else {
let (files, _) = finder
.call(opts, &mut Vec::new(), |stdin, _| {
let (files, _, _) = finder
.call(opts, |stdin, _| {
stdin
.write_all(all_files.as_bytes())
.context("Unable to prompt cheats to import")?;
Expand Down
16 changes: 6 additions & 10 deletions src/finder/mod.rs
Expand Up @@ -19,12 +19,7 @@ pub enum FinderChoice {
}

pub trait Finder {
fn call<F>(
&self,
opts: Opts,
files: &mut Vec<String>,
stdin_fn: F,
) -> Result<(String, Option<VariableMap>), Error>
fn call<F>(&self, opts: Opts, stdin_fn: F) -> Result<(String, Option<VariableMap>, Vec<String>), Error>
where
F: Fn(&mut process::ChildStdin, &mut Vec<String>) -> Result<Option<VariableMap>, Error>;
}
Expand All @@ -50,9 +45,8 @@ impl Finder for FinderChoice {
fn call<F>(
&self,
finder_opts: Opts,
files: &mut Vec<String>,
stdin_fn: F,
) -> Result<(String, Option<VariableMap>), Error>
) -> Result<(String, Option<VariableMap>, Vec<String>), Error>
where
F: Fn(&mut process::ChildStdin, &mut Vec<String>) -> Result<Option<VariableMap>, Error>,
{
Expand Down Expand Up @@ -174,11 +168,13 @@ impl Finder for FinderChoice {
.stdin
.as_mut()
.ok_or_else(|| anyhow!("Unable to acquire stdin of finder"))?;
let result_map = stdin_fn(stdin, files).context("Failed to pass data to finder")?;

let mut files = vec![];
let result_map = stdin_fn(stdin, &mut files).context("Failed to pass data to finder")?;

let out = child.wait_with_output().context("Failed to wait for finder")?;

let output = parse(out, finder_opts).context("Unable to get output")?;
Ok((output, result_map))
Ok((output, result_map, files))
}
}

0 comments on commit ab7289e

Please sign in to comment.