1mod download_acceleration;
2mod download_speed;
3mod file_size;
4
5use rust_decimal::Decimal;
6
7pub use download_acceleration::DownloadAcceleration;
8pub use download_speed::DownloadSpeed;
9pub use file_size::FileSize;
10
11#[derive(Debug, Clone, Copy)]
15pub enum SizeStandard {
16 SI,
20 IEC,
24}
25
26pub(crate) fn format_parts(
30 mut value: Decimal,
31 base: Decimal,
32 units: &'static [&'static str],
33) -> (String, &'static str) {
34 let mut unit_index = 0;
35
36 while value >= base && unit_index < units.len() - 1 {
37 value /= base;
38 unit_index += 1;
39 }
40
41 let formatted_value = format_decimal_value(value);
42 (formatted_value, units[unit_index])
43}
44
45#[inline]
53pub(crate) fn format_decimal_value(value: Decimal) -> String {
54 if value < Decimal::from(10) {
55 let mut rounded = value.round_dp(2);
56 rounded.rescale(2);
57 rounded.to_string()
58 } else {
59 let mut rounded = value.round_dp(1);
60 rounded.rescale(1);
61 rounded.to_string()
62 }
63}