summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2021-04-15 09:41:18 -0300
committerGitHub <noreply@github.com>2021-04-15 09:41:18 -0300
commitab7289e3aa4c09fee551f66cab6fa6b56d35bc02 (patch)
tree6083002e28dae8c3182670cfa6673de6b5c69a59
parentd5d939bc9676ba0995addd6b8d1fdd1f96265643 (diff)
Remove unnecessary uses of vector of files (#507)
-rw-r--r--src/actor.rs6
-rw-r--r--src/cmds/core.rs8
-rw-r--r--src/cmds/repo.rs12
-rw-r--r--src/finder/mod.rs16
4 files changed, 18 insertions, 24 deletions
diff --git a/src/actor.rs b/src/actor.rs
index 5850c15..2827050 100644
--- a/src/actor.rs
+++ b/src/actor.rs
@@ -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")?;
@@ -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();
diff --git a/src/cmds/core.rs b/src/cmds/core.rs
index 96343b0..f3f95ad 100644
--- a/src/cmds/core.rs
+++ b/src/cmds/core.rs
@@ -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() {
@@ -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(())
}
diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs
index 4dcadd4..f3ffd7b 100644
--- a/src/cmds/repo.rs
+++ b/src/cmds/repo.rs
@@ -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")?;
@@ -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")?;
@@ -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")?;
diff --git a/src/finder/mod.rs b/src/finder/mod.rs
index fafe535..0bb1ed1 100644
--- a/src/finder/mod.rs
+++ b/src/finder/mod.rs
@@ -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>;
}
@@ -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>,
{
@@ -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))
}
}