Skip to content

Commit 3b1bbc2

Browse files
committed
Rust 2024
1 parent c4a7b2a commit 3b1bbc2

32 files changed

+350
-359
lines changed

Cargo.lock

Lines changed: 37 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
version = "1.5.5"
77
description = "Arbitrary-precision unit-aware calculator"
8-
edition = "2021"
8+
edition = "2024"
99
homepage = "https://github.com/printfn/fend"
1010
repository = "https://github.com/printfn/fend"
1111
keywords = ["calculator", "cli", "conversion", "math", "tool"]

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fend-core.workspace = true
1616
home = "0.5.11"
1717
rand = { version = "0.9.0", default-features = false, features = ["thread_rng"] }
1818
rustyline = { version = "15.0.0", default-features = false, features = ["with-file-history", "custom-bindings"] }
19-
serde = { version = "1.0.217", default-features = false }
19+
serde = { version = "1.0.218", default-features = false }
2020
toml = { version = "0.8.20", default-features = false, features = ["parse"] }
2121
minreq = { version = "2.13.2", default-features = false, optional = true }
2222

cli/src/config.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl serde::de::Visitor<'_> for ExchangeRateSourceVisitor {
4343
return Err(serde::de::Error::unknown_variant(
4444
v,
4545
&["EU", "UN", "disabled"],
46-
))
46+
));
4747
}
4848
})
4949
}
@@ -103,7 +103,9 @@ impl<'de> serde::de::Visitor<'de> for ConfigVisitor {
103103
} else if enable_colors == "always".into() {
104104
result.enable_colors = true;
105105
} else {
106-
eprintln!("Error: unknown config setting for `{key}`, expected one of `'never'`, `'auto'` or `'always'`");
106+
eprintln!(
107+
"Error: unknown config setting for `{key}`, expected one of `'never'`, `'auto'` or `'always'`"
108+
);
107109
}
108110
seen_enable_colors = true;
109111
}
@@ -151,7 +153,7 @@ impl<'de> serde::de::Visitor<'de> for ConfigVisitor {
151153
return Err(serde::de::Error::invalid_value(
152154
serde::de::Unexpected::Str(v),
153155
&"`ignore` or `warn`",
154-
))
156+
));
155157
}
156158
};
157159
}
@@ -174,7 +176,7 @@ impl<'de> serde::de::Visitor<'de> for ConfigVisitor {
174176
return Err(serde::de::Error::invalid_value(
175177
serde::de::Unexpected::Str(v),
176178
&"`default`, `dot` or `comma`",
177-
))
179+
));
178180
}
179181
};
180182
seen_decimal_separator_style = true;

cli/src/custom_units.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl serde::de::Visitor<'_> for CustomUnitAttributeVisitor {
3838
"is-long-prefix",
3939
"alias",
4040
],
41-
))
41+
));
4242
}
4343
})
4444
}
@@ -82,7 +82,9 @@ impl<'de> serde::Deserialize<'de> for CustomUnitDefinition {
8282
type Value = CustomUnitDefinition;
8383

8484
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
85-
formatter.write_str("a custom unit definition, with properties `singular`, `plural`, `definition` and `attribute`")
85+
formatter.write_str(
86+
"a custom unit definition, with properties `singular`, `plural`, `definition` and `attribute`",
87+
)
8688
}
8789

8890
fn visit_map<V: serde::de::MapAccess<'de>>(

cli/src/exchange_rates.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::Error;
12
use crate::config::{self, ExchangeRateSource};
23
use crate::file_paths;
3-
use crate::Error;
44
use std::{error, fmt, fs, io::Write, time};
55

66
const MAX_AGE: u64 = 86400 * 3;
@@ -126,7 +126,7 @@ fn parse_exchange_rates_un(exchange_rates: &str) -> Result<Vec<(String, f64)>, E
126126
None if exchange_rates
127127
== "\r\n\t</UN_OPERATIONAL_RATES>\r\n</UN_OPERATIONAL_RATES_DATASET>" =>
128128
{
129-
break
129+
break;
130130
}
131131
None => return Err(err.into()),
132132
};

cli/src/file_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn mark_dir_as_hidden_impl(path: &ffi::OsStr) -> Result<(), u32> {
168168
use std::os::windows::ffi::OsStrExt;
169169
use windows_sys::Win32::{
170170
Foundation::GetLastError,
171-
Storage::FileSystem::{SetFileAttributesW, FILE_ATTRIBUTE_HIDDEN},
171+
Storage::FileSystem::{FILE_ATTRIBUTE_HIDDEN, SetFileAttributesW},
172172
};
173173

174174
let path = path.encode_wide().chain(Some(0)).collect::<Vec<u16>>();

cli/src/terminal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn init_prompt<'a>(
2626
context: &context::Context<'a>,
2727
) -> Result<PromptState<'a>, Box<dyn error::Error>> {
2828
use rustyline::{
29-
config::Builder, history::FileHistory, Cmd, Editor, KeyCode, KeyEvent, Modifiers, Movement,
29+
Cmd, Editor, KeyCode, KeyEvent, Modifiers, Movement, config::Builder, history::FileHistory,
3030
};
3131

3232
let mut rl = Editor::<helper::Helper<'_>, FileHistory>::with_config(

core/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::num::{Base, FormattingStyle, Number, Range, RangeBound};
66
use crate::result::FResult;
77
use crate::scope::Scope;
88
use crate::serialize::{Deserialize, Serialize};
9-
use crate::value::{built_in_function::BuiltInFunction, ApplyMulHandling, Value};
9+
use crate::value::{ApplyMulHandling, Value, built_in_function::BuiltInFunction};
1010
use crate::{Attrs, Context, DecimalSeparatorStyle};
1111
use std::borrow::Cow;
1212
use std::sync::Arc;

core/src/date.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) use day_of_week::DayOfWeek;
1111
pub(crate) use month::Month;
1212
use year::Year;
1313

14-
use crate::{error::FendError, ident::Ident, result::FResult, value::Value, Interrupt};
14+
use crate::{Interrupt, error::FendError, ident::Ident, result::FResult, value::Value};
1515

1616
#[derive(Copy, Clone, Eq, PartialEq)]
1717
pub(crate) struct Date {

core/src/date/day.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::result::FResult;
21
use crate::FendError;
2+
use crate::result::FResult;
33
use crate::{Deserialize, Serialize};
44
use std::fmt;
55
use std::io;

core/src/date/month.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::result::FResult;
21
use crate::FendError;
2+
use crate::result::FResult;
33
use crate::{
44
date::Year,
55
serialize::{Deserialize, Serialize},

core/src/date/parser.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ fn parse_char(s: &str) -> Result<(char, &str), ()> {
1313

1414
fn parse_specific_char(s: &str, c: char) -> Result<&str, ()> {
1515
let (ch, s) = parse_char(s)?;
16-
if ch == c {
17-
Ok(s)
18-
} else {
19-
Err(())
20-
}
16+
if ch == c { Ok(s) } else { Err(()) }
2117
}
2218

2319
fn parse_digit(s: &str) -> Result<(i32, &str), ()> {

core/src/date/year.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ impl Year {
4747
}
4848

4949
pub(crate) fn number_of_days(self) -> u16 {
50-
if self.is_leap_year() {
51-
366
52-
} else {
53-
365
54-
}
50+
if self.is_leap_year() { 366 } else { 365 }
5551
}
5652

5753
pub(crate) fn serialize(self, write: &mut impl io::Write) -> FResult<()> {

0 commit comments

Comments
 (0)