Skip to content

Commit 975b20d

Browse files
refactor: upgrade to rust 2024 edition
1 parent bf551ef commit 975b20d

File tree

87 files changed

+322
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+322
-266
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
resolver = '2'
2+
resolver = "3"
33

44
members = [
55
"packages/*",
@@ -17,7 +17,7 @@ description = "Alignment, mutation calling, phylogenetic placement, clade assign
1717
repository = "https://github.com/nextstrain/nextclade"
1818
documentation = "https://docs.nextstrain.org/projects/nextclade/en/stable/"
1919
homepage = "https://clades.nextstrain.org/"
20-
edition = "2021"
20+
edition = "2024"
2121
license = "MIT"
2222
publish = false
2323
authors = ["Nextstrain team"]
@@ -105,6 +105,7 @@ keyword_idents = { level = "warn", priority = -1 }
105105
nonstandard_style = { level = "warn", priority = -1 }
106106
rust_2018_idioms = { level = "warn", priority = -1 }
107107
rust_2021_compatibility = { level = "warn", priority = -1 }
108+
rust_2024_compatibility = { level = "warn", priority = -1 }
108109

109110
# Disable some of the lints enabled by default
110111
# https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html
@@ -248,6 +249,7 @@ use_debug = "allow"
248249
use_self = "allow"
249250
useless_transmute = "allow"
250251
wildcard_enum_match_arm = "allow"
252+
ref_option = "allow"
251253

252254

253255
[workspace.lints.rustdoc]

packages/nextclade-cli/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use ctor::ctor;
22
use eyre::Report;
33
use nextclade::{
44
io::json_schema::JsonSchemaOutputFormat,
5-
schema::schema::{generate_schema, NextcladeFileFormat},
6-
utils::global_init::{global_init, GlobalInitConfig},
5+
schema::schema::{NextcladeFileFormat, generate_schema},
6+
utils::global_init::{GlobalInitConfig, global_init},
77
};
88
use std::path::PathBuf;
99

packages/nextclade-cli/src/cli/nextclade_cli.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ use crate::cli::verbosity::Verbosity;
88
use crate::io::http_client::ProxyConfig;
99
use clap::builder::styling;
1010
use clap::{ArgGroup, CommandFactory, Parser, Subcommand, ValueEnum, ValueHint};
11-
use clap_complete::{generate, Shell};
11+
use clap_complete::{Shell, generate};
1212
use clap_complete_fig::Fig;
13-
use eyre::{eyre, ContextCompat, Report, WrapErr};
13+
use eyre::{ContextCompat, Report, WrapErr, eyre};
1414
use itertools::Itertools;
1515
use nextclade::io::console::CliColorMode;
1616
use nextclade::io::fs::add_extension;
1717
use nextclade::run::params::NextcladeInputParamsOptional;
18-
use nextclade::schema::schema::{cli_handle_schema, NextcladeSchemaArgs};
18+
use nextclade::schema::schema::{NextcladeSchemaArgs, cli_handle_schema};
1919
use nextclade::sort::params::NextcladeSeqSortParams;
20-
use nextclade::utils::global_init::{global_init, GlobalInitConfig};
20+
use nextclade::utils::global_init::{GlobalInitConfig, global_init};
2121
use nextclade::{getenv, make_error};
2222
use std::fmt::Debug;
2323
use std::io;
@@ -926,10 +926,11 @@ pub fn nextclade_get_output_filenames(run_args: &mut NextcladeRunArgs) -> Result
926926
}
927927
}
928928

929-
if let Some(output_translations) = output_translations {
930-
if !output_translations.contains("{cds}") {
931-
return make_error!(
932-
r#"
929+
if let Some(output_translations) = output_translations
930+
&& !output_translations.contains("{cds}")
931+
{
932+
return make_error!(
933+
r#"
933934
Expected `--output-translations` argument to contain a template string containing template variable {{cds}} (with curly braces), but received:
934935
935936
{output_translations}
@@ -940,8 +941,7 @@ Example for bash shell:
940941
--output-translations='output_dir/nextclade.cds_translation.{{cds}}.fasta'
941942
942943
"#
943-
);
944-
}
944+
);
945945
}
946946

947947
let all_outputs_are_missing = [
@@ -1155,7 +1155,9 @@ pub fn nextclade_check_column_config_args(run_args: &NextcladeRunArgs) -> Result
11551155
} = &run_args.outputs;
11561156

11571157
if !output_columns_selection.is_empty() && [output_all, output_csv, output_tsv].iter().all(|arg| arg.is_none()) {
1158-
return make_error!("The `--output-columns-selection` argument configures column-based output formats and can only be used when one or more of the column-based file outputs is requested, i.e. together with one or multiple of `--output-all`, `--output-csv`, `--output-tsv`.");
1158+
return make_error!(
1159+
"The `--output-columns-selection` argument configures column-based output formats and can only be used when one or more of the column-based file outputs is requested, i.e. together with one or multiple of `--output-all`, `--output-csv`, `--output-tsv`."
1160+
);
11591161
}
11601162

11611163
Ok(())

packages/nextclade-cli/src/cli/nextclade_dataset_get.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::dataset::dataset_download::{dataset_dir_download, dataset_zip_downloa
33
use crate::io::http_client::HttpClient;
44
use eyre::{Report, WrapErr};
55
use itertools::Itertools;
6-
use log::{warn, LevelFilter};
6+
use log::{LevelFilter, warn};
77
use nextclade::io::dataset::{Dataset, DatasetsIndexJson};
88
use nextclade::make_error;
99
use nextclade::utils::info::{this_package_version, this_package_version_str};
@@ -78,8 +78,8 @@ pub fn dataset_http_get(http: &HttpClient, name: impl AsRef<str>, tag: Option<&S
7878
// ...and if no tags matching, display error
7979
let suggestions_msg = format_suggestions(dataset.tags(), tag);
8080
make_error!(
81-
"Dataset '{name}' is found, but requested version tag for it not found: '{tag}'.{suggestions_msg}\n\nType `nextclade dataset list --name='{name}'` to show available version tags for this dataset or use --tag='latest' or omit the --tag argument to use the latest version tag.",
82-
)
81+
"Dataset '{name}' is found, but requested version tag for it not found: '{tag}'.{suggestions_msg}\n\nType `nextclade dataset list --name='{name}'` to show available version tags for this dataset or use --tag='latest' or omit the --tag argument to use the latest version tag.",
82+
)
8383
}
8484
}
8585
},

packages/nextclade-cli/src/cli/nextclade_dataset_list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::dataset::dataset_download::download_datasets_index_json;
33
use crate::dataset::dataset_table::format_dataset_table;
44
use crate::io::http_client::HttpClient;
55
use eyre::Report;
6-
use itertools::{chain, Itertools};
7-
use log::{warn, LevelFilter};
6+
use itertools::{Itertools, chain};
7+
use log::{LevelFilter, warn};
88
use nextclade::io::dataset::{Dataset, DatasetListJson, DatasetsIndexJson};
9-
use nextclade::io::json::{json_stringify, JsonPretty};
9+
use nextclade::io::json::{JsonPretty, json_stringify};
1010
use nextclade::utils::info::this_package_version;
1111

1212
pub fn nextclade_dataset_list(

packages/nextclade-cli/src/cli/nextclade_loop.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use nextclade::analyze::pcr_primers::PcrPrimer;
77
use nextclade::gene::gene_map_display::gene_map_to_table_string;
88
use nextclade::graph::graph::Graph;
99
use nextclade::io::fasta::{FastaReader, FastaRecord};
10-
use nextclade::io::json::{json_write, JsonPretty};
10+
use nextclade::io::json::{JsonPretty, json_write};
1111
use nextclade::io::nextclade_csv_column_config::CsvColumnConfig;
1212
use nextclade::io::nwk_writer::nwk_write_to_file;
1313
use nextclade::run::nextclade_wasm::{AnalysisInitialData, AnalysisOutput, Nextclade};
@@ -161,10 +161,8 @@ pub fn nextclade_run(mut run_args: NextcladeRunArgs) -> Result<(), Report> {
161161
}
162162

163163
for record in result_receiver {
164-
if should_write_tree {
165-
if let Ok(AnalysisOutput { analysis_result, .. }) = &record.outputs_or_err {
166-
outputs.push(analysis_result.clone());
167-
}
164+
if should_write_tree && let Ok(AnalysisOutput { analysis_result, .. }) = &record.outputs_or_err {
165+
outputs.push(analysis_result.clone());
168166
}
169167
output_writer
170168
.write_record(record)

packages/nextclade-cli/src/cli/nextclade_read_annotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use nextclade::features::feature_tree::FeatureTree;
44
use nextclade::gene::gene_map::GeneMap;
55
use nextclade::gene::gene_map_display::gene_map_to_table_string;
66
use nextclade::io::file::open_file_or_stdin;
7-
use nextclade::io::json::{json_or_yaml_write, json_stringify, JsonPretty};
7+
use nextclade::io::json::{JsonPretty, json_or_yaml_write, json_stringify};
88
use std::io::Read;
99

1010
pub fn nextclade_read_annotation(args: &NextcladeReadAnnotationArgs) -> Result<(), Report> {

packages/nextclade-cli/src/cli/nextclade_seq_sort.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ use crate::io::http_client::HttpClient;
44
use console::style;
55
use eyre::{Report, WrapErr};
66
use itertools::Itertools;
7-
use log::{trace, LevelFilter};
7+
use log::{LevelFilter, trace};
88
use maplit::btreemap;
99
use nextclade::io::csv::CsvStructFileWriter;
1010
use nextclade::io::fasta::{FastaReader, FastaRecord, FastaWriter};
1111
use nextclade::io::fs::path_to_string;
1212
use nextclade::make_error;
13-
use nextclade::sort::minimizer_index::{MinimizerIndexJson, MINIMIZER_INDEX_ALGO_VERSION};
13+
use nextclade::sort::minimizer_index::{MINIMIZER_INDEX_ALGO_VERSION, MinimizerIndexJson};
1414
use nextclade::sort::minimizer_search::{
15-
find_best_datasets, find_best_suggestion_for_seq, run_minimizer_search, MinimizerSearchDatasetResult,
16-
MinimizerSearchRecord,
15+
MinimizerSearchDatasetResult, MinimizerSearchRecord, find_best_datasets, find_best_suggestion_for_seq,
16+
run_minimizer_search,
1717
};
1818
use nextclade::utils::option::{OptionMapMutFallible, OptionMapRefFallible};
1919
use nextclade::utils::string::truncate;
2020
use ordered_float::OrderedFloat;
2121
use schemars::JsonSchema;
2222
use serde::Serialize;
23-
use std::collections::btree_map::Entry::{Occupied, Vacant};
2423
use std::collections::BTreeMap;
24+
use std::collections::btree_map::Entry::{Occupied, Vacant};
2525
use std::path::{Path, PathBuf};
2626
use std::str::FromStr;
2727
use tinytemplate::TinyTemplate;
@@ -74,7 +74,11 @@ pub fn nextclade_seq_sort(args: &NextcladeSortArgs) -> Result<(), Report> {
7474
format!(": {server_versions}")
7575
};
7676

77-
make_error!("No compatible reference minimizer index data is found for this dataset sever. Cannot proceed. \n\nThis version of Nextclade supports index versions up to '{}', but the server has {}.\n\nTry to to upgrade Nextclade to the latest version and/or contact dataset server maintainers.", MINIMIZER_INDEX_ALGO_VERSION, server_versions)
77+
make_error!(
78+
"No compatible reference minimizer index data is found for this dataset sever. Cannot proceed. \n\nThis version of Nextclade supports index versions up to '{}', but the server has {}.\n\nTry to to upgrade Nextclade to the latest version and/or contact dataset server maintainers.",
79+
MINIMIZER_INDEX_ALGO_VERSION,
80+
server_versions
81+
)
7882
}
7983
}?;
8084

@@ -483,10 +487,11 @@ fn check_args(args: &NextcladeSortArgs) -> Result<(), Report> {
483487
);
484488
}
485489

486-
if let Some(output) = output {
487-
if !output.contains("{name}") {
488-
return make_error!(
489-
r#"
490+
if let Some(output) = output
491+
&& !output.contains("{name}")
492+
{
493+
return make_error!(
494+
r#"
490495
Expected `--output` argument to contain a template string containing template variable {{name}} (with curly braces), but received:
491496
492497
{output}
@@ -497,8 +502,7 @@ Example for bash shell:
497502
--output='outputs/{{name}}/sorted.fasta.gz'
498503
499504
"#
500-
);
501-
}
505+
);
502506
}
503507

504508
Ok(())

packages/nextclade-cli/src/cli/print_help_markdown.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ If you have Nextclade CLI installed, you can type `nextclade --help` to read the
1818
"#,
1919
)?;
2020

21-
let help = replace(&help, "Nextclade is a part of Nextstrain: https://nextstrain.org\n\nDocumentation: https://docs.nextstrain.org/projects/nextclade\nNextclade Web: https://clades.nextstrain.org\nPublication: https://doi.org/10.21105/joss.03773", "Nextclade is a part of Nextstrain: [https://nextstrain.org](https://nextstrain.org)\n\nDocumentation: [https://docs.nextstrain.org/projects/nextclade](https://docs.nextstrain.org/projects/nextclade)\n\nNextclade Web: [https://clades.nextstrain.org](https://clades.nextstrain.org)\n\nPublication: [https://doi.org/10.21105/joss.03773](https://doi.org/10.21105/joss.03773)")?;
21+
let help = replace(
22+
&help,
23+
"Nextclade is a part of Nextstrain: https://nextstrain.org\n\nDocumentation: https://docs.nextstrain.org/projects/nextclade\nNextclade Web: https://clades.nextstrain.org\nPublication: https://doi.org/10.21105/joss.03773",
24+
"Nextclade is a part of Nextstrain: [https://nextstrain.org](https://nextstrain.org)\n\nDocumentation: [https://docs.nextstrain.org/projects/nextclade](https://docs.nextstrain.org/projects/nextclade)\n\nNextclade Web: [https://clades.nextstrain.org](https://clades.nextstrain.org)\n\nPublication: [https://doi.org/10.21105/joss.03773](https://doi.org/10.21105/joss.03773)",
25+
)?;
2226

2327
let help = replace(&help, "(.*)— REMOVED(.*)", "")?;
2428
let help = replace(&help, "(.*)— RENAMED(.*)", "")?;

packages/nextclade-cli/src/dataset/dataset_download.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ use crate::cli::nextclade_cli::{NextcladeRunArgs, NextcladeRunInputArgs};
22
use crate::cli::nextclade_dataset_get::{dataset_file_http_get, dataset_http_get};
33
use crate::io::http_client::{HttpClient, ProxyConfig};
44
use color_eyre::{Section, SectionExt};
5-
use eyre::{eyre, ContextCompat, Report, WrapErr};
5+
use eyre::{ContextCompat, Report, WrapErr, eyre};
66
use itertools::Itertools;
7-
use log::{warn, LevelFilter};
7+
use log::{LevelFilter, warn};
88
use nextclade::analyze::virus_properties::VirusProperties;
9-
use nextclade::gene::gene_map::{filter_gene_map, GeneMap};
9+
use nextclade::gene::gene_map::{GeneMap, filter_gene_map};
1010
use nextclade::io::dataset::{Dataset, DatasetsIndexJson};
1111
use nextclade::io::fasta::{read_one_fasta_from_file, read_one_fasta_from_str};
1212
use nextclade::io::file::create_file_or_stdout;
1313
use nextclade::io::fs::{ensure_dir, has_extension, read_file_to_string};
1414
use nextclade::run::nextclade_wasm::{NextcladeParams, NextcladeParamsOptional};
15-
use nextclade::tree::tree::{check_ref_seq_mismatch, AuspiceTree};
15+
use nextclade::tree::tree::{AuspiceTree, check_ref_seq_mismatch};
1616
use nextclade::utils::fs::list_files_recursive;
1717
use nextclade::utils::option::OptionMapRefFallible;
18-
use nextclade::utils::string::{format_list, surround_with_quotes, Indent};
18+
use nextclade::utils::string::{Indent, format_list, surround_with_quotes};
1919
use nextclade::{make_error, make_internal_error, o};
2020
use std::collections::BTreeSet;
2121
use std::fs::File;
@@ -159,10 +159,10 @@ pub fn dataset_zip_load(
159159

160160
verify_dataset_files(&virus_properties, zip.file_names());
161161

162-
if let Some(tree) = &tree {
163-
if let Some(tree_ref) = tree.root_sequence() {
164-
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
165-
}
162+
if let Some(tree) = &tree
163+
&& let Some(tree_ref) = tree.root_sequence()
164+
{
165+
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
166166
}
167167

168168
Ok(NextcladeParams {
@@ -217,7 +217,10 @@ fn verify_dataset_files<'a, T: AsRef<str> + 'a + ?Sized>(
217217
format_list(Indent(2), declared.iter()),
218218
format_list(Indent(2), present.iter()),
219219
));
220-
warn!("When reading dataset: {}\nThis is not an error. Nextclade ignores unknown file declarations and undeclared files. But this could be a mistake by the dataset author. For example, there could be a typo in pathogen.json file declaration, or a file could have been added to the dataset, but not declared in the pathogen.json. In this case, Nextclade analysis could be missing some of the features intended by the author. Contact the author to resolve this. It could also be that the dataset contains files for a newer version of Nextclade, and that the currently used version does not recognize these files. In which case try to upgrade Nextclade.", warnings.join("\n"));
220+
warn!(
221+
"When reading dataset: {}\nThis is not an error. Nextclade ignores unknown file declarations and undeclared files. But this could be a mistake by the dataset author. For example, there could be a typo in pathogen.json file declaration, or a file could have been added to the dataset, but not declared in the pathogen.json. In this case, Nextclade analysis could be missing some of the features intended by the author. Contact the author to resolve this. It could also be that the dataset contains files for a newer version of Nextclade, and that the currently used version does not recognize these files. In which case try to upgrade Nextclade.",
222+
warnings.join("\n")
223+
);
221224
}
222225
}
223226

@@ -305,10 +308,10 @@ pub fn dataset_dir_load(
305308
.collect_vec();
306309
verify_dataset_files(&virus_properties, dataset_dir_files.iter());
307310

308-
if let Some(tree) = &tree {
309-
if let Some(tree_ref) = tree.root_sequence() {
310-
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
311-
}
311+
if let Some(tree) = &tree
312+
&& let Some(tree_ref) = tree.root_sequence()
313+
{
314+
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
312315
}
313316

314317
Ok(NextcladeParams {
@@ -354,10 +357,10 @@ pub fn dataset_json_load(
354357
.map_ref_fallible(GeneMap::from_path)
355358
.wrap_err("When parsing genome annotation")?;
356359

357-
if let (Some(tree), Some(ref_record)) = (&tree, &ref_record) {
358-
if let Some(tree_ref) = tree.root_sequence() {
359-
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
360-
}
360+
if let (Some(tree), Some(ref_record)) = (&tree, &ref_record)
361+
&& let Some(tree_ref) = tree.root_sequence()
362+
{
363+
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
361364
}
362365

363366
NextcladeParamsOptional {
@@ -408,10 +411,10 @@ pub fn dataset_individual_files_load(
408411
.map_ref_fallible(AuspiceTree::from_path)
409412
.wrap_err("When reading reference tree JSON")?;
410413

411-
if let Some(tree) = &tree {
412-
if let Some(tree_ref) = tree.root_sequence() {
413-
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
414-
}
414+
if let Some(tree) = &tree
415+
&& let Some(tree_ref) = tree.root_sequence()
416+
{
417+
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
415418
}
416419

417420
Ok(NextcladeParams {
@@ -489,10 +492,10 @@ pub fn dataset_str_download_and_load(
489492
.map_ref_fallible(AuspiceTree::from_str)
490493
.wrap_err("When reading reference tree from dataset")?;
491494

492-
if let Some(tree) = &tree {
493-
if let Some(tree_ref) = tree.root_sequence() {
494-
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
495-
}
495+
if let Some(tree) = &tree
496+
&& let Some(tree_ref) = tree.root_sequence()
497+
{
498+
check_ref_seq_mismatch(&ref_record.seq, tree_ref)?;
496499
}
497500

498501
Ok(NextcladeParams {

0 commit comments

Comments
 (0)