Skip to content

Commit

Permalink
clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gerdreiss committed Nov 1, 2021
1 parent 883bcf9 commit ac0743a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
29 changes: 14 additions & 15 deletions api/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl RemoteCandidate {
pub fn versions(&self) -> &Vec<RemoteVersion> {
&self.versions
}
pub fn with_versions(&mut self, versions: &Vec<RemoteVersion>) -> &mut Self {
pub fn with_versions(&mut self, versions: &[RemoteVersion]) -> &mut Self {
self.versions = versions.to_vec();
self
}
Expand Down Expand Up @@ -106,7 +106,7 @@ impl RemoteVersion {
fn get_status_and_usage(
&self,
local_versions: &HashMap<String, bool>,
version: &String,
version: &str,
) -> (&str, &str) {
(
if local_versions.contains_key(version) {
Expand All @@ -128,7 +128,7 @@ impl FromStr for RemoteVersion {

fn from_str(input: &str) -> Result<Self, Self::Err> {
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),
Expand Down Expand Up @@ -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) {
Expand All @@ -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(' ');
}
}

Expand Down Expand Up @@ -245,13 +244,13 @@ pub fn fetch_remote_candidates() -> Result<Vec<RemoteCandidate>, 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(
Expand All @@ -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<String, SdkmanApiError> {
Expand All @@ -292,7 +291,7 @@ fn parse_candidates(input: String) -> Vec<RemoteCandidate> {
.collect()
}

fn parse_available_versions(input: &String) -> Vec<RemoteVersion> {
fn parse_available_versions(input: &str) -> Vec<RemoteVersion> {
if input.contains("Available Java Versions") {
parse_available_java_versions(input)
} else {
Expand All @@ -310,7 +309,7 @@ fn parse_available_versions(input: &String) -> Vec<RemoteVersion> {
}
}

fn parse_available_java_versions(input: &String) -> Vec<RemoteVersion> {
fn parse_available_java_versions(input: &str) -> Vec<RemoteVersion> {
input
.lines()
.skip(5)
Expand Down
2 changes: 1 addition & 1 deletion api/src/util.rs
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
27 changes: 14 additions & 13 deletions ui/src/candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ impl Default for SdkmanApp {

impl SdkmanApp {
pub fn new(
remote_candidates: &Vec<RemoteCandidate>,
local_candidates: &Vec<LocalCandidate>,
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 {
Expand Down Expand Up @@ -232,7 +233,7 @@ impl SdkmanApp {
.to_string(),
)
})
.map(|c| c.clone())
.cloned()
.collect();
*selected_candidate = None;
}
Expand All @@ -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);
Expand Down Expand Up @@ -495,7 +496,7 @@ impl SdkmanApp {

fn render_search_dialog(
ctx: &CtxRef,
candidates: &Vec<Candidate>,
candidates: &[Candidate],
selected_candidate: &mut Option<Candidate>,
candidate_search_dialog: &mut bool,
candidate_search_term: &mut String,
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_), _) => {
Expand Down

0 comments on commit ac0743a

Please sign in to comment.