Skip to content

Commit eea130e

Browse files
committed
avoiding using LazyLock in Rust
1 parent 198ecd1 commit eea130e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

modules/mexpreval/src/models.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@ use std::ffi::CStr;
22
use std::os::raw::c_char;
33
use std::{env, slice};
44
use std::str::FromStr;
5-
use std::sync::LazyLock;
65
use meval::{Context, Expr};
76
use crate::{OdeExpr};
87

9-
static DEF_YDOT: LazyLock<f64> = LazyLock::new(|| {
10-
env::var("CUQDYN_DEF_YDOT")
11-
.unwrap_or_else(|_| "0.0".to_string())
12-
.parse()
13-
.unwrap_or(0.0)
14-
});
15-
168
pub trait Model {
179
fn eval(&self, t: f64, y: &[f64], ydot: &mut [f64], p: &[f64]);
1810
}
@@ -90,14 +82,20 @@ impl Model for GenericModel<'_> {
9082
ydot[i] = expr.eval_with_context(&self.ctx).unwrap();
9183

9284
if !ydot[i].is_finite() {
85+
let def = env::var("CUQDYN_DEF_YDOT")
86+
.unwrap_or_else(|_| "0.0".to_string())
87+
.parse()
88+
.unwrap_or(0.0);
89+
9390
eprintln!(
9491
"Expression {} evaluated to {} with params {:?}, setting to default value {}",
9592
i + 1,
9693
ydot[i],
9794
p,
98-
*DEF_YDOT
95+
def
9996
);
100-
ydot[i] = *DEF_YDOT;
97+
98+
ydot[i] = def;
10199
}
102100
}
103101
}

0 commit comments

Comments
 (0)