Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE: Update to Rust 2024 edition #310

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ironcalc_base"
version = "0.3.0"
authors = ["Nicolás Hatcher <[email protected]>"]
edition = "2021"
edition = "2024"
homepage = "https://www.ironcalc.com"
repository = "https://github.com/ironcalc/ironcalc/"
description = "Open source spreadsheet engine"
Expand Down
2 changes: 1 addition & 1 deletion base/examples/formulas_and_errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ironcalc_base::{types::CellType, Model};
use ironcalc_base::{Model, types::CellType};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut model = Model::new_empty("formulas-and-errors", "en", "UTC")?;
Expand Down
2 changes: 1 addition & 1 deletion base/examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ironcalc_base::{cell::CellValue, Model};
use ironcalc_base::{Model, cell::CellValue};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut model = Model::new_empty("hello-world", "en", "UTC")?;
Expand Down
2 changes: 1 addition & 1 deletion base/src/diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
expressions::{
parser::{
move_formula::ref_is_in_area,
stringify::{to_string, to_string_displaced, DisplaceData},
stringify::{DisplaceData, to_string, to_string_displaced},
walk::forward_references,
},
types::{Area, CellReferenceIndex, CellReferenceRC},
Expand Down
8 changes: 5 additions & 3 deletions base/src/expressions/lexer/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ impl Lexer {
Ok(n) => n,
Err(_) => {
return Err(self
.set_error(&format!("Failed parsing row {}", row_left), position))
.set_error(&format!("Failed parsing row {}", row_left), position));
}
};
let row_right = match row_right.parse::<i32>() {
Ok(n) => n,
Err(_) => {
return Err(self
.set_error(&format!("Failed parsing row {}", row_right), position))
return Err(self.set_error(
&format!("Failed parsing row {}", row_right),
position,
));
}
};
if row_left > LAST_ROW {
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/move_formula.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
stringify::{stringify_reference, DisplaceData},
Node, Reference,
stringify::{DisplaceData, stringify_reference},
};
use crate::{
constants::{LAST_COLUMN, LAST_ROW},
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/tests/test_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

use crate::expressions::lexer::LexerMode;
use crate::expressions::parser::stringify::{
to_rc_format, to_string, to_string_displaced, DisplaceData,
DisplaceData, to_rc_format, to_string, to_string_displaced,
};
use crate::expressions::parser::{Node, Parser};
use crate::expressions::types::CellReferenceRC;
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/tests/test_issue_155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::collections::HashMap;

use crate::expressions::parser::stringify::to_string;
use crate::expressions::parser::Parser;
use crate::expressions::parser::stringify::to_string;
use crate::expressions::types::CellReferenceRC;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/tests/test_move_formula.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use crate::expressions::parser::move_formula::{move_formula, MoveContext};
use crate::expressions::parser::Parser;
use crate::expressions::parser::move_formula::{MoveContext, move_formula};
use crate::expressions::types::{Area, CellReferenceRC};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/tests/test_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

use crate::expressions::lexer::LexerMode;

use crate::expressions::parser::stringify::{to_rc_format, to_string};
use crate::expressions::parser::Parser;
use crate::expressions::parser::stringify::{to_rc_format, to_string};
use crate::expressions::types::CellReferenceRC;

struct Formula<'a> {
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/tests/test_stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::collections::HashMap;

use crate::expressions::parser::stringify::to_string;
use crate::expressions::parser::Parser;
use crate::expressions::parser::stringify::to_string;
use crate::expressions::types::CellReferenceRC;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion base/src/expressions/parser/walk.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{move_formula::ref_is_in_area, Node};
use super::{Node, move_formula::ref_is_in_area};

use crate::expressions::types::{Area, CellReferenceIndex};

Expand Down
8 changes: 2 additions & 6 deletions base/src/formatter/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn format_number(value_original: f64, format: &str, locale: &Locale) -> Form
text: "#VALUE!".to_owned(),
color: None,
error: Some(e),
}
};
}
};
for token in tokens {
Expand Down Expand Up @@ -391,11 +391,7 @@ pub fn format_number(value_original: f64, format: &str, locale: &Locale) -> Form
if l_exp <= p.exponent_digit_count {
if !(number_index < 0 && digit.kind == '#') {
let c = if number_index < 0 {
if digit.kind == '?' {
' '
} else {
'0'
}
if digit.kind == '?' { ' ' } else { '0' }
} else {
exponent_part[number_index as usize]
};
Expand Down
2 changes: 1 addition & 1 deletion base/src/formatter/test/test_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
formatter::format::format_number,
locale::{get_locale, Locale},
locale::{Locale, get_locale},
};

fn get_default_locale() -> &'static Locale {
Expand Down
14 changes: 7 additions & 7 deletions base/src/functions/date_and_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Model {
error: Error::NUM,
origin: cell,
message: "Out of range parameters for date".to_string(),
}
};
}
};
let day = date.day() as f64;
Expand All @@ -54,7 +54,7 @@ impl Model {
error: Error::NUM,
origin: cell,
message: "Out of range parameters for date".to_string(),
}
};
}
};
let month = date.month() as f64;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Model {
error: Error::NUM,
origin: cell,
message: "Out of range parameters for date".to_string(),
}
};
}
};
if serial_number > MAXIMUM_DATE_SERIAL_NUMBER as i64 {
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Model {
error: Error::NUM,
origin: cell,
message: "Out of range parameters for date".to_string(),
}
};
}
};
let year = date.year() as f64;
Expand All @@ -216,7 +216,7 @@ impl Model {
error: Error::NUM,
origin: cell,
message: "Out of range parameters for date".to_string(),
}
};
}
};

Expand Down Expand Up @@ -266,7 +266,7 @@ impl Model {
error: Error::ERROR,
origin: cell,
message: "Invalid date".to_string(),
}
};
}
};
// 693_594 is computed as:
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Model {
error: Error::ERROR,
origin: cell,
message: "Invalid date".to_string(),
}
};
}
};
// 693_594 is computed as:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

use std::f64::consts::FRAC_2_PI;

use super::bessel_util::{high_word, split_words, FRAC_2_SQRT_PI, HUGE};
use super::bessel_util::{FRAC_2_SQRT_PI, HUGE, high_word, split_words};

// R0/S0 on [0, 2.00]
const R02: f64 = 1.562_499_999_999_999_5e-2; // 0x3F8FFFFF, 0xFFFFFFFD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

use std::f64::consts::FRAC_2_PI;

use super::bessel_util::{high_word, split_words, FRAC_2_SQRT_PI, HUGE};
use super::bessel_util::{FRAC_2_SQRT_PI, HUGE, high_word, split_words};

// R0/S0 on [0,2]
const R00: f64 = -6.25e-2; // 0xBFB00000, 0x00000000
Expand Down
14 changes: 3 additions & 11 deletions base/src/functions/engineering/transcendental/bessel_jn_yn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use super::{
bessel_j0_y0::{j0, y0},
bessel_j1_y1::{j1, y1},
bessel_util::{split_words, FRAC_2_SQRT_PI},
bessel_util::{FRAC_2_SQRT_PI, split_words},
};

// Special cases are:
Expand Down Expand Up @@ -232,11 +232,7 @@ pub(crate) fn jn(n: i32, x: f64) -> f64 {
}
}
};
if sign == 1 {
-b
} else {
b
}
if sign == 1 { -b } else { b }
}

// Yn returns the order-n Bessel function of the second kind.
Expand Down Expand Up @@ -321,9 +317,5 @@ pub(crate) fn yn(n: i32, x: f64) -> f64 {
}
b
};
if sign > 0 {
b
} else {
-b
}
if sign > 0 { b } else { -b }
}
6 changes: 1 addition & 5 deletions base/src/functions/engineering/transcendental/erf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,5 @@ pub(crate) fn erf(x: f64) -> f64 {
}

let res = t * f64::exp(-x_abs * x_abs + 0.5 * (cof[0] + ty * d) - dd);
if x < 0.0 {
res - 1.0
} else {
1.0 - res
}
if x < 0.0 { res - 1.0 } else { 1.0 - res }
}
18 changes: 7 additions & 11 deletions base/src/functions/financial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ impl Model {
error: error.0,
origin: cell,
message: error.1,
}
};
}
};
CalcResult::Number(ipmt)
Expand Down Expand Up @@ -762,7 +762,7 @@ impl Model {
error: error.0,
origin: cell,
message: error.1,
}
};
}
};
CalcResult::Number(ppmt)
Expand Down Expand Up @@ -1075,7 +1075,7 @@ impl Model {
error,
origin: cell,
message,
}
};
}
}
};
Expand All @@ -1096,7 +1096,7 @@ impl Model {
error,
origin: cell,
message,
}
};
}
}
};
Expand Down Expand Up @@ -1634,7 +1634,7 @@ impl Model {
error: error.0,
origin: cell,
message: error.1,
}
};
}
}
}
Expand Down Expand Up @@ -1702,7 +1702,7 @@ impl Model {
error: error.0,
origin: cell,
message: error.1,
}
};
}
}
}
Expand Down Expand Up @@ -1750,11 +1750,7 @@ impl Model {
rate = 1.0
};
let value = if rate == 1.0 {
if period == 1.0 {
cost
} else {
0.0
}
if period == 1.0 { cost } else { 0.0 }
} else {
cost * (1.0 - rate).powf(period - 1.0)
};
Expand Down
6 changes: 3 additions & 3 deletions base/src/functions/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ impl Model {
{
match defined_name {
ParsedDefinedName::CellReference(reference) => {
return CalcResult::Number(reference.sheet as f64 + 1.0)
return CalcResult::Number(reference.sheet as f64 + 1.0);
}
ParsedDefinedName::RangeReference(range) => {
return CalcResult::Number(range.left.sheet as f64 + 1.0)
return CalcResult::Number(range.left.sheet as f64 + 1.0);
}
ParsedDefinedName::InvalidDefinedNameFormula => {
return CalcResult::Error {
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Model {
error: Error::NAME,
origin: cell,
message: format!("Name not found: {name}"),
}
};
}
arg => {
// Now it should be the name of a sheet
Expand Down
2 changes: 1 addition & 1 deletion base/src/functions/statistical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl Model {
Error::ERROR,
cell,
format!("Invalid worksheet index: '{}'", first_range.left.sheet),
)
);
}
};
let max_row = dimension.max_row;
Expand Down
2 changes: 1 addition & 1 deletion base/src/functions/subtotal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
calc_result::CalcResult,
expressions::{
parser::{parse_range, Node},
parser::{Node, parse_range},
token::Error,
types::CellReferenceIndex,
},
Expand Down
Loading
Loading