1#![warn(clippy::all)]
8
9pub mod config;
10pub mod error;
11
12pub mod adaptive_sort;
14pub mod args;
15pub mod core_sort;
16pub mod external_sort;
17pub mod hash_sort;
18pub mod locale;
19pub mod radix_sort;
20pub mod simd_compare;
21pub mod zero_copy;
22
23pub use config::{SortConfig, SortMode, SortOrder};
25pub use error::{SortError, SortResult};
26
27pub const EXIT_SUCCESS: i32 = 0;
29pub const EXIT_FAILURE: i32 = 1;
30pub const SORT_FAILURE: i32 = 2;
31
32pub fn sort(config: &SortConfig, input_files: &[String]) -> SortResult<i32> {
34 let args = crate::args::SortArgs {
36 files: input_files.to_vec(),
37 output: config.output_file.clone(),
38 reverse: config.reverse,
39 numeric_sort: matches!(config.mode, crate::config::SortMode::Numeric),
40 general_numeric_sort: matches!(config.mode, crate::config::SortMode::GeneralNumeric),
41 human_numeric_sort: matches!(config.mode, crate::config::SortMode::HumanNumeric),
42 version_sort: matches!(config.mode, crate::config::SortMode::Version),
43 random_sort: matches!(config.mode, crate::config::SortMode::Random),
44 random_seed: None, ignore_case: config.ignore_case,
46 unique: config.unique,
47 stable: config.stable,
48 field_separator: config.field_separator,
49 zero_terminated: config.zero_terminated,
50 check: config.check,
51 merge: config.merge,
52 };
53
54 let core_sort = crate::core_sort::CoreSort::new(args, config.clone());
55 core_sort
56 .sort()
57 .map_err(|e| SortError::internal(&e.to_string()))?;
58 Ok(EXIT_SUCCESS)
59}