Skip to content

Commit

Permalink
chore: apply clippy lints for rust v1.73.0 (#507)
Browse files Browse the repository at this point in the history
chore: apply clippy lints after rust v1.73.0
  • Loading branch information
kayagokalp authored Nov 8, 2023
1 parent becb25a commit f718941
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
43 changes: 21 additions & 22 deletions ci/compare-versions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,13 @@ fn get_workflow_runs(repo: &str) -> Result<WorkflowRunApiResponse> {
let resp = handle
.get(&github_actions_runs_api_url)
.call()
.expect(&format!("Could not get workflow runs for {}", repo));
.unwrap_or_else(|_| panic!("Could not get workflow runs for {}", repo));

let mut data = Vec::new();
resp.into_reader().read_to_end(&mut data)?;

Ok(
serde_json::from_str(&String::from_utf8_lossy(&data)).expect(&format!(
"Failed to deserialize a workflow run for repo {}",
repo
)),
)
Ok(serde_json::from_str(&String::from_utf8_lossy(&data))
.unwrap_or_else(|_| panic!("Failed to deserialize a workflow run for repo {}", repo)))
}

fn get_latest_release_version(repo: &str) -> Result<Version> {
Expand Down Expand Up @@ -127,28 +123,31 @@ fn collect_new_versions(channel: &Document, repo: &str) -> Result<Vec<Version>>
}

fn parse_latest_indexed_version(channel: &Document, package: &str) -> Version {
Version::from_str(channel["pkg"][package]["version"].as_str().expect(&format!(
"Could not parse {} version str from {} toml",
package, channel
)))
.expect(&format!("Could not create version from {}", package))
Version::from_str(
channel["pkg"][package]["version"]
.as_str()
.unwrap_or_else(|| {
panic!(
"Could not parse {} version str from {} toml",
package, channel
)
}),
)
.unwrap_or_else(|_| panic!("Could not create version from {}", package))
}

fn fmt_versions(forc_version: &str, fuel_core_version: &str) -> String {
format!("forc-{}@fuel-core-{}", forc_version, fuel_core_version)
}

fn print_selected_versions<'a>(
forc_versions: &[Version],
fuel_core_versions: &[Version],
) -> String {
fn print_selected_versions(forc_versions: &[Version], fuel_core_versions: &[Version]) -> String {
let mut output = String::new();

for forc in forc_versions {
for fuel_core in fuel_core_versions {
let formatted_versions = fmt_versions(&forc.to_string(), &fuel_core.to_string());
output.push_str(&formatted_versions);
output.push_str("\n");
output.push('\n');
}
}

Expand All @@ -160,7 +159,7 @@ fn print_selected_versions<'a>(
fn compare_rest() -> Result<()> {
let handle = ureq::builder().user_agent("fuelup").build();

let toml_resp = match handle.get(&CHANNEL_FUEL_LATEST_TOML_URL).call() {
let toml_resp = match handle.get(CHANNEL_FUEL_LATEST_TOML_URL).call() {
Ok(r) => r
.into_string()
.expect("Could not convert channel to string"),
Expand Down Expand Up @@ -223,16 +222,16 @@ fn get_latest_version(repo: &str) -> Result<Version> {
// would guarantee the existence of the release binaries. Releases can be published and be available
// without the binaries being ready yet, which causes inconsistency.
if let Some(latest_run) = get_workflow_runs(repo)?.workflow_runs.first() {
return Ok(Version::from_str(&latest_run.head_branch[1..])?);
Ok(Version::from_str(&latest_run.head_branch[1..])?)
} else {
return Ok(get_latest_release_version(repo)?);
};
get_latest_release_version(repo)
}
}

fn compare_compatibility() -> Result<()> {
let handle = ureq::builder().user_agent("fuelup").build();

let toml_resp = match handle.get(&CHANNEL_FUEL_LATEST_TOML_URL).call() {
let toml_resp = match handle.get(CHANNEL_FUEL_LATEST_TOML_URL).call() {
Ok(r) => r
.into_string()
.expect("Could not convert channel to string"),
Expand Down
3 changes: 2 additions & 1 deletion component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl Components {
.get(c)
.expect("Failed to parse components.toml")
})
.filter_map(|c| c.is_plugin.is_none().then(|| c.clone()))
.filter(|&c| c.is_plugin.is_none())
.cloned()
.collect();

main_components.sort_by_key(|c| c.name.clone());
Expand Down
7 changes: 5 additions & 2 deletions src/ops/fuelup_component/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ fn format_installable_component_info(name: &str, latest_version: &str) -> String
}

fn format_forc_default_plugins(plugin_executables: Vec<String>) -> String {
use std::fmt::Write;
format!(
" - {}\n",
plugin_executables
.iter()
.filter(|c| *c != component::FORC)
.map(|s| format!("{s} "))
.collect::<String>(),
.fold(String::new(), |mut output, b| {
let _ = write!(output, "{b}");
output
})
)
}

Expand Down

0 comments on commit f718941

Please sign in to comment.