Skip to content

Commit 8455130

Browse files
committed
debug log errors in all compute functions
1 parent 86eae17 commit 8455130

File tree

2 files changed

+78
-85
lines changed

2 files changed

+78
-85
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "floccus"
3-
version = "0.4.0-alpha.5"
3+
version = "0.4.0-alpha.6"
44
authors = ["Jakub Lewandowski <[email protected]>"]
55
edition = "2021"
66
description = "Formulae for air thermodynamic calculations"
@@ -25,7 +25,6 @@ uom = { version = "0.36", default-features = false, features = [
2525
"f32",
2626
"f64",
2727
] }
28-
cfg-if = "1.0"
2928

3029
[lib]
3130
doctest = false

src/formulas/traits.rs

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,20 @@ pub trait Formula1<O: ThermodynamicQuantity, I1: ThermodynamicQuantity> {
1414
#[allow(clippy::missing_errors_doc)]
1515
fn validate_inputs(i1: I1) -> Result<(), InputError>;
1616

17-
#[allow(clippy::missing_errors_doc)]
1817
#[allow(missing_docs)]
18+
#[allow(clippy::missing_errors_doc)]
1919
#[inline]
20-
fn compute(i1: I1) -> Result<O, InputError> {
21-
cfg_if::cfg_if! {
22-
if #[cfg(feature = "debug")] {
23-
cfg_if::cfg_if! {
24-
if #[cfg(debug_assertions)] {
25-
Self::validate_inputs_loggerr(i1)?;
26-
}
27-
}
28-
} else {
29-
Self::validate_inputs(i1)?;
30-
}
31-
}
32-
33-
Ok(Self::compute_unchecked(i1))
20+
#[cfg(not(feature = "debug"))]
21+
fn validate_inputs_internal(i1: I1) -> Result<(), InputError> {
22+
Self::validate_inputs(i1)
3423
}
3524

3625
#[cfg(feature = "debug")]
3726
#[cfg(debug_assertions)]
38-
#[inline(always)]
27+
#[inline]
3928
#[allow(missing_docs)]
4029
#[allow(clippy::missing_errors_doc)]
41-
fn validate_inputs_loggerr(i1: I1) -> Result<(), InputError> {
30+
fn validate_inputs_internal(i1: I1) -> Result<(), InputError> {
4231
use std::any::type_name;
4332

4433
Self::validate_inputs(i1).or_else(|err| {
@@ -53,6 +42,14 @@ pub trait Formula1<O: ThermodynamicQuantity, I1: ThermodynamicQuantity> {
5342
})
5443
}
5544

45+
#[allow(clippy::missing_errors_doc)]
46+
#[allow(missing_docs)]
47+
#[inline]
48+
fn compute(i1: I1) -> Result<O, InputError> {
49+
Self::validate_inputs_internal(i1)?;
50+
Ok(Self::compute_unchecked(i1))
51+
}
52+
5653
#[allow(missing_docs)]
5754
#[allow(clippy::missing_errors_doc)]
5855
fn compute_vec(i1: &[I1]) -> Result<Vec<O>, InputError> {
@@ -71,7 +68,7 @@ pub trait Formula1<O: ThermodynamicQuantity, I1: ThermodynamicQuantity> {
7168
let i1: ArrayView<I1, D> = i1.into();
7269

7370
Zip::from(i1)
74-
.fold_while(Ok(()), |_, &i1| match Self::validate_inputs(i1) {
71+
.fold_while(Ok(()), |_, &i1| match Self::validate_inputs_internal(i1) {
7572
Ok(_) => FoldWhile::Continue(Ok(())),
7673
Err(e) => FoldWhile::Done(Err(e)),
7774
})
@@ -99,7 +96,7 @@ pub trait Formula1<O: ThermodynamicQuantity, I1: ThermodynamicQuantity> {
9996
let i1: ArrayView<I1, D> = i1.into();
10097

10198
Zip::from(i1)
102-
.fold_while(Ok(()), |_, &a| match Self::validate_inputs(a) {
99+
.fold_while(Ok(()), |_, &a| match Self::validate_inputs_internal(a) {
103100
Ok(_) => FoldWhile::Continue(Ok(())),
104101
Err(e) => FoldWhile::Done(Err(e)),
105102
})
@@ -117,31 +114,20 @@ pub trait Formula2<O: ThermodynamicQuantity, I1: ThermodynamicQuantity, I2: Ther
117114
#[allow(clippy::missing_errors_doc)]
118115
fn validate_inputs(i1: I1, i2: I2) -> Result<(), InputError>;
119116

120-
#[allow(clippy::missing_errors_doc)]
121117
#[allow(missing_docs)]
118+
#[allow(clippy::missing_errors_doc)]
122119
#[inline]
123-
fn compute(i1: I1, i2: I2) -> Result<O, InputError> {
124-
cfg_if::cfg_if! {
125-
if #[cfg(feature = "debug")] {
126-
cfg_if::cfg_if! {
127-
if #[cfg(debug_assertions)] {
128-
Self::validate_inputs_loggerr(i1,i2)?;
129-
}
130-
}
131-
} else {
132-
Self::validate_inputs(i1,i2)?;
133-
}
134-
}
135-
136-
Ok(Self::compute_unchecked(i1, i2))
120+
#[cfg(not(feature = "debug"))]
121+
fn validate_inputs_internal(i1: I1, i2: I2) -> Result<(), InputError> {
122+
Self::validate_inputs(i1, i2)
137123
}
138124

139125
#[cfg(feature = "debug")]
140126
#[cfg(debug_assertions)]
141-
#[inline(always)]
127+
#[inline]
142128
#[allow(missing_docs)]
143129
#[allow(clippy::missing_errors_doc)]
144-
fn validate_inputs_loggerr(i1: I1, i2: I2) -> Result<(), InputError> {
130+
fn validate_inputs_internal(i1: I1, i2: I2) -> Result<(), InputError> {
145131
use std::any::type_name;
146132

147133
Self::validate_inputs(i1, i2).or_else(|err| {
@@ -157,6 +143,14 @@ pub trait Formula2<O: ThermodynamicQuantity, I1: ThermodynamicQuantity, I2: Ther
157143
})
158144
}
159145

146+
#[allow(clippy::missing_errors_doc)]
147+
#[allow(missing_docs)]
148+
#[inline]
149+
fn compute(i1: I1, i2: I2) -> Result<O, InputError> {
150+
Self::validate_inputs_internal(i1, i2)?;
151+
Ok(Self::compute_unchecked(i1, i2))
152+
}
153+
160154
#[allow(missing_docs)]
161155
#[allow(clippy::missing_errors_doc)]
162156
fn compute_vec(i1: &[I1], i2: &[I2]) -> Result<Vec<O>, InputError> {
@@ -187,9 +181,11 @@ pub trait Formula2<O: ThermodynamicQuantity, I1: ThermodynamicQuantity, I2: Ther
187181

188182
Zip::from(i1)
189183
.and(i2)
190-
.fold_while(Ok(()), |_, &i1, &i2| match Self::validate_inputs(i1, i2) {
191-
Ok(_) => FoldWhile::Continue(Ok(())),
192-
Err(e) => FoldWhile::Done(Err(e)),
184+
.fold_while(Ok(()), |_, &i1, &i2| {
185+
match Self::validate_inputs_internal(i1, i2) {
186+
Ok(_) => FoldWhile::Continue(Ok(())),
187+
Err(e) => FoldWhile::Done(Err(e)),
188+
}
193189
})
194190
.into_inner()?;
195191

@@ -229,9 +225,11 @@ pub trait Formula2<O: ThermodynamicQuantity, I1: ThermodynamicQuantity, I2: Ther
229225

230226
Zip::from(i1)
231227
.and(i2)
232-
.fold_while(Ok(()), |_, &i1, &i2| match Self::validate_inputs(i1, i2) {
233-
Ok(_) => FoldWhile::Continue(Ok(())),
234-
Err(e) => FoldWhile::Done(Err(e)),
228+
.fold_while(Ok(()), |_, &i1, &i2| {
229+
match Self::validate_inputs_internal(i1, i2) {
230+
Ok(_) => FoldWhile::Continue(Ok(())),
231+
Err(e) => FoldWhile::Done(Err(e)),
232+
}
235233
})
236234
.into_inner()?;
237235

@@ -255,31 +253,20 @@ pub trait Formula3<
255253
#[allow(clippy::missing_errors_doc)]
256254
fn validate_inputs(i1: I1, i2: I2, i3: I3) -> Result<(), InputError>;
257255

258-
#[allow(clippy::missing_errors_doc)]
259256
#[allow(missing_docs)]
257+
#[allow(clippy::missing_errors_doc)]
260258
#[inline]
261-
fn compute(i1: I1, i2: I2, i3: I3) -> Result<O, InputError> {
262-
cfg_if::cfg_if! {
263-
if #[cfg(feature = "debug")] {
264-
cfg_if::cfg_if! {
265-
if #[cfg(debug_assertions)] {
266-
Self::validate_inputs_loggerr(i1, i2, i3)?;
267-
}
268-
}
269-
} else {
270-
Self::validate_inputs(i1,i2,i3)?;
271-
}
272-
}
273-
274-
Ok(Self::compute_unchecked(i1, i2, i3))
259+
#[cfg(not(feature = "debug"))]
260+
fn validate_inputs_internal(i1: I1, i2: I2, i3: I3) -> Result<(), InputError> {
261+
Self::validate_inputs(i1, i2, i3)
275262
}
276263

277264
#[cfg(feature = "debug")]
278265
#[cfg(debug_assertions)]
279-
#[inline(always)]
266+
#[inline]
280267
#[allow(missing_docs)]
281268
#[allow(clippy::missing_errors_doc)]
282-
fn validate_inputs_loggerr(i1: I1, i2: I2, i3: I3) -> Result<(), InputError> {
269+
fn validate_inputs_internal(i1: I1, i2: I2, i3: I3) -> Result<(), InputError> {
283270
use std::any::type_name;
284271

285272
Self::validate_inputs(i1, i2, i3).or_else(|err| {
@@ -296,6 +283,14 @@ pub trait Formula3<
296283
})
297284
}
298285

286+
#[allow(clippy::missing_errors_doc)]
287+
#[allow(missing_docs)]
288+
#[inline]
289+
fn compute(i1: I1, i2: I2, i3: I3) -> Result<O, InputError> {
290+
Self::validate_inputs_internal(i1, i2, i3)?;
291+
Ok(Self::compute_unchecked(i1, i2, i3))
292+
}
293+
299294
#[allow(missing_docs)]
300295
#[allow(clippy::missing_errors_doc)]
301296
fn compute_vec(i1: &[I1], i2: &[I2], i3: &[I3]) -> Result<Vec<O>, InputError> {
@@ -332,12 +327,13 @@ pub trait Formula3<
332327
Zip::from(i1)
333328
.and(i2)
334329
.and(i3)
335-
.fold_while(Ok(()), |_, &i1, &i2, &i3| {
336-
match Self::validate_inputs(i1, i2, i3) {
330+
.fold_while(
331+
Ok(()),
332+
|_, &i1, &i2, &i3| match Self::validate_inputs_internal(i1, i2, i3) {
337333
Ok(_) => FoldWhile::Continue(Ok(())),
338334
Err(e) => FoldWhile::Done(Err(e)),
339-
}
340-
})
335+
},
336+
)
341337
.into_inner()?;
342338

343339
Ok(Zip::from(i1)
@@ -383,12 +379,13 @@ pub trait Formula3<
383379
Zip::from(i1)
384380
.and(i2)
385381
.and(i3)
386-
.fold_while(Ok(()), |_, &i1, &i2, &i3| {
387-
match Self::validate_inputs(i1, i2, i3) {
382+
.fold_while(
383+
Ok(()),
384+
|_, &i1, &i2, &i3| match Self::validate_inputs_internal(i1, i2, i3) {
388385
Ok(_) => FoldWhile::Continue(Ok(())),
389386
Err(e) => FoldWhile::Done(Err(e)),
390-
}
391-
})
387+
},
388+
)
392389
.into_inner()?;
393390

394391
Ok(Zip::from(i1)
@@ -413,31 +410,28 @@ pub trait Formula4<
413410
#[allow(clippy::missing_errors_doc)]
414411
fn validate_inputs(i1: I1, i2: I2, i3: I3, i4: I4) -> Result<(), InputError>;
415412

413+
#[allow(missing_docs)]
414+
#[allow(clippy::missing_errors_doc)]
415+
#[inline]
416+
#[cfg(not(feature = "debug"))]
417+
fn validate_inputs_internal(i1: I1, i2: I2, i3: I3, i4: I4) -> Result<(), InputError> {
418+
Self::validate_inputs(i1, i2, i3, i4)
419+
}
420+
416421
#[allow(clippy::missing_errors_doc)]
417422
#[allow(missing_docs)]
418423
#[inline]
419424
fn compute(i1: I1, i2: I2, i3: I3, i4: I4) -> Result<O, InputError> {
420-
cfg_if::cfg_if! {
421-
if #[cfg(feature = "debug")] {
422-
cfg_if::cfg_if! {
423-
if #[cfg(debug_assertions)] {
424-
Self::validate_inputs_loggerr(i1,i2,i3,i4)?;
425-
}
426-
}
427-
} else {
428-
Self::validate_inputs(i1,i2,i3,i4)?;
429-
}
430-
}
431-
425+
Self::validate_inputs_internal(i1, i2, i3, i4)?;
432426
Ok(Self::compute_unchecked(i1, i2, i3, i4))
433427
}
434428

435429
#[cfg(feature = "debug")]
436430
#[cfg(debug_assertions)]
437-
#[inline(always)]
431+
#[inline]
438432
#[allow(missing_docs)]
439433
#[allow(clippy::missing_errors_doc)]
440-
fn validate_inputs_loggerr(i1: I1, i2: I2, i3: I3, i4: I4) -> Result<(), InputError> {
434+
fn validate_inputs_internal(i1: I1, i2: I2, i3: I3, i4: I4) -> Result<(), InputError> {
441435
use std::any::type_name;
442436

443437
Self::validate_inputs(i1, i2, i3, i4).or_else(|err| {
@@ -499,7 +493,7 @@ pub trait Formula4<
499493
.and(i4)
500494
.fold_while(
501495
Ok(()),
502-
|_, &i1, &i2, &i3, &i4| match Self::validate_inputs(i1, i2, i3, i4) {
496+
|_, &i1, &i2, &i3, &i4| match Self::validate_inputs_internal(i1, i2, i3, i4) {
503497
Ok(_) => FoldWhile::Continue(Ok(())),
504498
Err(e) => FoldWhile::Done(Err(e)),
505499
},
@@ -563,7 +557,7 @@ pub trait Formula4<
563557
.and(i4)
564558
.fold_while(
565559
Ok(()),
566-
|_, &i1, &i2, &i3, &i4| match Self::validate_inputs(i1, i2, i3, i4) {
560+
|_, &i1, &i2, &i3, &i4| match Self::validate_inputs_internal(i1, i2, i3, i4) {
567561
Ok(_) => FoldWhile::Continue(Ok(())),
568562
Err(e) => FoldWhile::Done(Err(e)),
569563
},

0 commit comments

Comments
 (0)