mirror of
https://github.com/starship/starship.git
synced 2024-11-25 17:54:08 +01:00
refactor: simplify iterator usage (#3017)
This commit is contained in:
parent
3933553486
commit
6598275e15
@ -141,7 +141,7 @@ where
|
||||
fn from_config(config: &'a Value) -> Option<Self> {
|
||||
let mut hm = Self::default();
|
||||
|
||||
for (x, y) in config.as_table()?.iter() {
|
||||
for (x, y) in config.as_table()? {
|
||||
hm.insert(x.clone(), T::from_config(y)?);
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ where
|
||||
fn from_config(config: &'a Value) -> Option<Self> {
|
||||
let mut im = Self::default();
|
||||
|
||||
for (x, y) in config.as_table()?.iter() {
|
||||
for (x, y) in config.as_table()? {
|
||||
im.insert(x.clone(), T::from_config(y)?);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ impl<'a> ModuleConfig<'a> for StarshipRootConfig<'a> {
|
||||
"env_var",
|
||||
]
|
||||
.iter()
|
||||
.chain(ALL_MODULES.iter())
|
||||
.chain(ALL_MODULES)
|
||||
.filter_map(|field| {
|
||||
let score = strsim::jaro_winkler(unknown, field);
|
||||
(score > 0.8).then(|| (score, field))
|
||||
|
@ -253,7 +253,7 @@ fn real_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
/// substitutions, in order, on the path. Any non-pair of strings is ignored.
|
||||
fn substitute_path(dir_string: String, substitutions: &IndexMap<String, &str>) -> String {
|
||||
let mut substituted_dir = dir_string;
|
||||
for substitution_pair in substitutions.iter() {
|
||||
for substitution_pair in substitutions {
|
||||
substituted_dir = substituted_dir.replace(substitution_pair.0, substitution_pair.1);
|
||||
}
|
||||
substituted_dir
|
||||
|
@ -186,7 +186,7 @@ fn try_find_nearby_global_json(current_dir: &Path, repo_root: Option<&Path>) ->
|
||||
// Check the parent directory, or otherwise the repository root, for a global.json
|
||||
let mut check_dirs = parent_dir
|
||||
.iter()
|
||||
.chain(repo_root.iter())
|
||||
.chain(&repo_root)
|
||||
.copied() // Copies the reference, not the Path itself
|
||||
.collect::<Vec<&Path>>();
|
||||
|
||||
|
@ -429,7 +429,7 @@ users: []
|
||||
.path(dir.path())
|
||||
.env(
|
||||
"KUBECONFIG",
|
||||
env::join_paths([&filename_cc, &filename_ctx].iter())
|
||||
env::join_paths([&filename_cc, &filename_ctx])
|
||||
.unwrap()
|
||||
.to_string_lossy(),
|
||||
)
|
||||
@ -444,7 +444,7 @@ users: []
|
||||
.path(dir.path())
|
||||
.env(
|
||||
"KUBECONFIG",
|
||||
env::join_paths([&filename_ctx, &filename_cc].iter())
|
||||
env::join_paths([&filename_ctx, &filename_cc])
|
||||
.unwrap()
|
||||
.to_string_lossy(),
|
||||
)
|
||||
|
@ -287,7 +287,7 @@ mod tests {
|
||||
None,
|
||||
];
|
||||
|
||||
for (status, name) in exit_values.iter().zip(exit_values_name.iter()) {
|
||||
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
||||
let expected = name.map(std::string::ToString::to_string);
|
||||
let actual = ModuleRenderer::new("status")
|
||||
.config(toml::toml! {
|
||||
@ -314,7 +314,7 @@ mod tests {
|
||||
None,
|
||||
];
|
||||
|
||||
for (status, name) in exit_values.iter().zip(exit_values_name.iter()) {
|
||||
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
||||
let expected = name.map(std::string::ToString::to_string);
|
||||
let actual = ModuleRenderer::new("status")
|
||||
.config(toml::toml! {
|
||||
@ -343,7 +343,7 @@ mod tests {
|
||||
Some("-3"),
|
||||
];
|
||||
|
||||
for (status, name) in exit_values.iter().zip(exit_values_name.iter()) {
|
||||
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
||||
let expected = name.map(std::string::ToString::to_string);
|
||||
let actual = ModuleRenderer::new("status")
|
||||
.config(toml::toml! {
|
||||
@ -362,7 +362,7 @@ mod tests {
|
||||
let exit_values = [1, 126, 127, 130, 131];
|
||||
let exit_values_name = ["🔴", "🚫", "🔍", "🧱", "⚡"];
|
||||
|
||||
for (status, name) in exit_values.iter().zip(exit_values_name.iter()) {
|
||||
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
||||
let expected = Some((*name).to_string());
|
||||
let actual = ModuleRenderer::new("status")
|
||||
.config(toml::toml! {
|
||||
@ -388,7 +388,7 @@ mod tests {
|
||||
let exit_values = [1, 126, 127, 130, 131];
|
||||
let exit_values_name = ["🔴", "🚫", "🔍", "🔴", "🔴"];
|
||||
|
||||
for (status, name) in exit_values.iter().zip(exit_values_name.iter()) {
|
||||
for (status, name) in exit_values.iter().zip(&exit_values_name) {
|
||||
let expected = Some((*name).to_string());
|
||||
let actual = ModuleRenderer::new("status")
|
||||
.config(toml::toml! {
|
||||
@ -424,7 +424,7 @@ mod tests {
|
||||
"PSF 🔴=🔴 🔴 🔴",
|
||||
];
|
||||
|
||||
for (status, rendered) in exit_values.iter().zip(exit_values_rendered.iter()) {
|
||||
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
||||
let main_exit_code = status[0];
|
||||
let pipe_exit_code = &status[1..];
|
||||
|
||||
@ -468,7 +468,7 @@ mod tests {
|
||||
"PSF 🔴=🔴1 🔴1 🔴1",
|
||||
];
|
||||
|
||||
for (status, rendered) in exit_values.iter().zip(exit_values_rendered.iter()) {
|
||||
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
||||
let main_exit_code = status[0];
|
||||
let pipe_exit_code = &status[1..];
|
||||
|
||||
@ -521,7 +521,7 @@ mod tests {
|
||||
let exit_values = [[130, 126, 131, 127], [1, 1, 1, 1]];
|
||||
let exit_values_rendered = ["F 🧱", "F 🔴"];
|
||||
|
||||
for (status, rendered) in exit_values.iter().zip(exit_values_rendered.iter()) {
|
||||
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
||||
let main_exit_code = status[0];
|
||||
let pipe_exit_code = &status[1..];
|
||||
|
||||
@ -561,7 +561,7 @@ mod tests {
|
||||
"PSF 1ERROR=🟢|🟢|🟢|🔴30|🔍|🚫|🔴3|⚡|🟢|⚡|🟢|🔴",
|
||||
];
|
||||
|
||||
for (status, rendered) in exit_values.iter().zip(exit_values_rendered.iter()) {
|
||||
for (status, rendered) in exit_values.iter().zip(&exit_values_rendered) {
|
||||
let main_exit_code = status[0];
|
||||
let pipe_exit_code = &status[1..];
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
extern crate winapi;
|
||||
|
||||
use std::iter;
|
||||
use std::mem;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::path::Path;
|
||||
@ -22,11 +21,7 @@ use winapi::um::winnt::{
|
||||
/// the current process access token and directory's security descriptor.
|
||||
/// Does not work for network drives and always returns true
|
||||
pub fn is_write_allowed(folder_path: &Path) -> std::result::Result<bool, &'static str> {
|
||||
let folder_name: Vec<u16> = folder_path
|
||||
.as_os_str()
|
||||
.encode_wide()
|
||||
.chain(iter::once(0))
|
||||
.collect();
|
||||
let folder_name: Vec<u16> = folder_path.as_os_str().encode_wide().chain([0]).collect();
|
||||
|
||||
if is_network_path(&folder_name) {
|
||||
log::info!(
|
||||
|
@ -300,13 +300,13 @@ fn compute_modules<'a>(context: &'a Context) -> Vec<Module<'a>> {
|
||||
for module in &modules {
|
||||
// Manually add all modules if `$all` is encountered
|
||||
if module == "all" {
|
||||
for module in PROMPT_ORDER.iter() {
|
||||
for module in PROMPT_ORDER {
|
||||
let modules = handle_module(module, context, &modules);
|
||||
prompt_order.extend(modules.into_iter());
|
||||
prompt_order.extend(modules);
|
||||
}
|
||||
} else {
|
||||
let modules = handle_module(module, context, &modules);
|
||||
prompt_order.extend(modules.into_iter());
|
||||
prompt_order.extend(modules);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream {
|
||||
let mut load_tokens = quote! {};
|
||||
let mut fields = quote! {};
|
||||
|
||||
for field in fields_named.named.iter() {
|
||||
for field in &fields_named.named {
|
||||
let ident = field.ident.as_ref().unwrap();
|
||||
|
||||
let new_load_tokens = quote! {
|
||||
|
Loading…
Reference in New Issue
Block a user