diff --git a/api/src/remote.rs b/api/src/remote.rs index 4ca4f33..16e1ec4 100644 --- a/api/src/remote.rs +++ b/api/src/remote.rs @@ -74,7 +74,7 @@ impl RemoteCandidate { pub fn versions(&self) -> &Vec { &self.versions } - pub fn with_versions(&mut self, versions: &Vec) -> &mut Self { + pub fn with_versions(&mut self, versions: &[RemoteVersion]) -> &mut Self { self.versions = versions.to_vec(); self } @@ -106,7 +106,7 @@ impl RemoteVersion { fn get_status_and_usage( &self, local_versions: &HashMap, - version: &String, + version: &str, ) -> (&str, &str) { ( if local_versions.contains_key(version) { @@ -128,7 +128,7 @@ impl FromStr for RemoteVersion { fn from_str(input: &str) -> Result { if input.contains(" | ") { - let parts: Vec<&str> = input.split_terminator("|").map(|s| s.trim()).collect(); + let parts: Vec<&str> = input.split_terminator('|').map(|s| s.trim()).collect(); Ok(RemoteVersion::JavaVersion( util::string_at(&parts, 0), util::string_at(&parts, 1), @@ -163,8 +163,7 @@ impl FromStr for RemoteCandidate { let mut homepage = String::new(); let mut default_version = String::new(); - let mut lines = input.lines(); - while let Some(line) = lines.next() { + for line in input.lines() { if line.is_empty() { continue; } else if URI_REGEX.is_match(line) { @@ -187,7 +186,7 @@ impl FromStr for RemoteCandidate { binary_name.push_str(line.split_whitespace().last().unwrap()); } else { description.push_str(line); - description.push_str(" "); + description.push(' '); } } @@ -245,13 +244,13 @@ pub fn fetch_remote_candidates() -> Result, SdkmanApiError> let url = prepare_url(Endpoint::CandidateList)?; let res = reqwest::blocking::get(url)?; let status: StatusCode = res.status(); - return if status.is_success() { + if status.is_success() { res.text() - .map(|text| parse_candidates(text)) - .map_err(|err| SdkmanApiError::RequestFailed(err)) + .map(parse_candidates) + .map_err(SdkmanApiError::RequestFailed) } else { Err(SdkmanApiError::ServerError(status.as_u16())) - }; + } } pub fn fetch_candidate_versions( @@ -262,13 +261,13 @@ pub fn fetch_candidate_versions( ))?; let res = reqwest::blocking::get(url)?; let status: StatusCode = res.status(); - return if status.is_success() { + if status.is_success() { res.text() .map(move |text| &*remote_candidate.with_versions(&parse_available_versions(&text))) - .map_err(|err| SdkmanApiError::RequestFailed(err)) + .map_err(SdkmanApiError::RequestFailed) } else { Err(SdkmanApiError::ServerError(status.as_u16())) - }; + } } fn prepare_url(endpoint: Endpoint) -> Result { @@ -292,7 +291,7 @@ fn parse_candidates(input: String) -> Vec { .collect() } -fn parse_available_versions(input: &String) -> Vec { +fn parse_available_versions(input: &str) -> Vec { if input.contains("Available Java Versions") { parse_available_java_versions(input) } else { @@ -310,7 +309,7 @@ fn parse_available_versions(input: &String) -> Vec { } } -fn parse_available_java_versions(input: &String) -> Vec { +fn parse_available_java_versions(input: &str) -> Vec { input .lines() .skip(5) diff --git a/api/src/util.rs b/api/src/util.rs index 992eb1d..f6b18c7 100644 --- a/api/src/util.rs +++ b/api/src/util.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -pub fn string_at(parts: &Vec<&str>, index: usize) -> String { +pub fn string_at(parts: &[&str], index: usize) -> String { parts .get(index) .map(|p| String::from_str(p).unwrap_or_default()) diff --git a/ui/src/candidates.rs b/ui/src/candidates.rs index 1edf8e8..3b3823a 100644 --- a/ui/src/candidates.rs +++ b/ui/src/candidates.rs @@ -91,16 +91,17 @@ impl Default for SdkmanApp { impl SdkmanApp { pub fn new( - remote_candidates: &Vec, - local_candidates: &Vec, + remote_candidates: &[RemoteCandidate], + local_candidates: &[LocalCandidate], ) -> SdkmanApp { - let mut app = SdkmanApp::default(); - app.candidates = remote_candidates - .iter() - .map(|remote_candidate| Candidate::from_model(remote_candidate)) - .collect(); - app.local_candidates = local_candidates.to_vec(); - app + SdkmanApp { + candidates: remote_candidates + .iter() + .map(|remote_candidate| Candidate::from_model(remote_candidate)) + .collect(), + local_candidates: local_candidates.to_vec(), + ..Default::default() + } } pub fn app_name(&self) -> &str { @@ -232,7 +233,7 @@ impl SdkmanApp { .to_string(), ) }) - .map(|c| c.clone()) + .cloned() .collect(); *selected_candidate = None; } @@ -242,7 +243,7 @@ impl SdkmanApp { }); } - fn render_error(ctx: &CtxRef, message: &String) { + fn render_error(ctx: &CtxRef, message: &str) { Window::new("Search").show(ctx, |ui| { ui.add_space(PADDING); ui.label(message); @@ -495,7 +496,7 @@ impl SdkmanApp { fn render_search_dialog( ctx: &CtxRef, - candidates: &Vec, + candidates: &[Candidate], selected_candidate: &mut Option, candidate_search_dialog: &mut bool, candidate_search_term: &mut String, @@ -508,7 +509,7 @@ impl SdkmanApp { ui.with_layout(Layout::left_to_right(), |ui| { let text_input = ui.text_edit_singleline(candidate_search_term); if text_input.lost_focus() && ui.input().key_pressed(Key::Enter) { - match candidates.into_iter().find(|candidate| { + match candidates.iter().find(|candidate| { candidate.name == *candidate_search_term || candidate .installation_instruction diff --git a/ui/src/main.rs b/ui/src/main.rs index 4ef0f4f..8220381 100644 --- a/ui/src/main.rs +++ b/ui/src/main.rs @@ -67,8 +67,10 @@ fn main() { ) { (Ok(remote_candidates), Ok(local_candidates)) => { let app = SdkmanApp::new(&remote_candidates, &local_candidates); - let mut win_option = NativeOptions::default(); - win_option.initial_window_size = Some(Vec2::new(1024., 960.)); + let win_option = NativeOptions { + initial_window_size: Some(Vec2::new(1024., 960.)), + ..Default::default() + }; run_native(Box::new(app), win_option); } (Err(_), _) => {