From 1a6fce18e1c10a4ece3e1658851187e1fd2f14bb Mon Sep 17 00:00:00 2001 From: marshmallow Date: Fri, 10 Jul 2026 12:53:59 +1000 Subject: [PATCH] convert vector builders to gen blocks --- crates/cli/src/cli.rs | 37 +++++++++--------- crates/cli/src/main.rs | 1 + crates/core/src/cache/mod.rs | 29 +++++++------- crates/core/src/commands/pty/logbuffer.rs | 11 +++--- crates/core/src/hive/node.rs | 47 +++++++++++++---------- crates/core/src/lib.rs | 2 +- 6 files changed, 66 insertions(+), 61 deletions(-) diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 86f66300..cb7f5130 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -369,44 +369,43 @@ fn node_names_completer(current: &std::ffi::OsStr) -> Vec { tokio::task::block_in_place(|| { let handle = Handle::current(); let modifiers = SubCommandModifiers::default(); - let mut completions = vec![]; - - if current.is_empty() || current == "-" { - completions.push( - CompletionCandidate::new("-").help(Some("Read stdin as --on arguments".into())), - ); - } let Ok(current_dir) = std::env::current_dir() else { - return completions; + return Vec::new(); }; let Ok(hive_location) = handle.block_on(get_hive_location( current_dir.display().to_string(), modifiers, )) else { - return completions; + return Vec::new(); }; let Some(current) = current.to_str() else { - return completions; + return Vec::new(); }; if current.starts_with('@') { - return vec![]; + return Vec::new(); } - if let Ok(names) = - handle.block_on(async { get_hive_node_names(&hive_location, modifiers).await }) - { - for name in names { - if name.starts_with(current) { - completions.push(CompletionCandidate::new(name)); + gen { + if current.is_empty() || current == "-" { + yield CompletionCandidate::new("-") + .help(Some("Read stdin as --on arguments".into())); + } + + if let Ok(names) = + handle.block_on(async { get_hive_node_names(&hive_location, modifiers).await }) + { + for name in names { + if name.starts_with(current) { + yield CompletionCandidate::new(name); + } } } } - - completions + .collect() }) } diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 9068616e..2420497e 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -3,6 +3,7 @@ #![deny(clippy::pedantic)] #![feature(default_field_values)] +#![feature(gen_blocks)] use std::process::Command; use std::sync::Arc; diff --git a/crates/core/src/cache/mod.rs b/crates/core/src/cache/mod.rs index 89934ea9..d23220c8 100644 --- a/crates/core/src/cache/mod.rs +++ b/crates/core/src/cache/mod.rs @@ -506,22 +506,23 @@ where previous_rowid = evaluation_paths.last().map_or(previous_rowid, |r| r.rowid); // build list of all store paths to check - let mut all_paths: Vec> = Vec::new(); - - for path in &evaluation_paths { - if let Ok(p) = SafeStorePath::::from_name_and_digest( - &path.flake_path_name, - &path.flake_path_digest, - ) { - all_paths.push(p); - } - if let Ok(p) = SafeStorePath::::from_name_and_digest( - &path.output_path_name, - &path.output_path_digest, - ) { - all_paths.push(p); + let all_paths: Vec> = gen { + for path in &evaluation_paths { + if let Ok(p) = SafeStorePath::::from_name_and_digest( + &path.flake_path_name, + &path.flake_path_digest, + ) { + yield p; + } + if let Ok(p) = SafeStorePath::::from_name_and_digest( + &path.output_path_name, + &path.output_path_digest, + ) { + yield p; + } } } + .collect(); // query which cached paths are valid in the nix store let valid_paths = match client.query_valid_paths(all_paths.clone(), false).await { diff --git a/crates/core/src/commands/pty/logbuffer.rs b/crates/core/src/commands/pty/logbuffer.rs index 1014a639..4469e620 100644 --- a/crates/core/src/commands/pty/logbuffer.rs +++ b/crates/core/src/commands/pty/logbuffer.rs @@ -25,13 +25,12 @@ impl LogBuffer { #[cfg(test)] fn take_lines(&mut self) -> Vec> { - let mut lines = vec![]; - - while let Some(line) = self.next_line() { - lines.push(line); + gen { + while let Some(line) = self.next_line() { + yield line; + } } - - lines + .collect() } } diff --git a/crates/core/src/hive/node.rs b/crates/core/src/hive/node.rs index d73b9215..3cc88f78 100644 --- a/crates/core/src/hive/node.rs +++ b/crates/core/src/hive/node.rs @@ -75,30 +75,35 @@ impl Target { modifiers: SubCommandModifiers, force_quiet: bool, ) -> Result, HiveLibError> { - let mut vector = vec![ - "-l".to_string(), - self.user.to_string(), - "-p".to_string(), - self.port.to_string(), - ]; - let mut options = vec![format!( - "StrictHostKeyChecking={}", - match modifiers.ssh_accept_host { - StrictHostKeyChecking::AcceptNew => "accept-new", - StrictHostKeyChecking::No => "no", - } - )]; - - options.extend(["BatchMode=yes".to_string()]); + let vector: Vec = gen { + yield "-l".to_string(); + yield self.user.to_string(); + yield "-p".to_string(); + yield self.port.to_string(); + + let options = [ + format!( + "StrictHostKeyChecking={}", + match modifiers.ssh_accept_host { + StrictHostKeyChecking::AcceptNew => "accept-new", + StrictHostKeyChecking::No => "no", + } + ), + "BatchMode=yes".to_string(), + ]; - vector.push("-o".to_string()); - vector.extend(options.into_iter().intersperse("-o".to_string())); + for option in options { + yield "-o".to_string(); + yield option; + } - if force_quiet { - vector.push("-q".to_string()); - } else if modifiers.ssh_verbosity > 0 { - vector.push(format!("-{}", "v".repeat(modifiers.ssh_verbosity))); + if force_quiet { + yield "-q".to_string(); + } else if modifiers.ssh_verbosity > 0 { + yield format!("-{}", "v".repeat(modifiers.ssh_verbosity)); + } } + .collect(); Ok(vector) } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 1b233387..0db3031e 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // Copyright 2024-2025 wire Contributors -#![feature(iter_intersperse)] #![feature(sync_nonpoison)] #![feature(nonpoison_mutex)] #![feature(default_field_values)] +#![feature(gen_blocks)] use std::{ collections::{HashMap, HashSet},