From 1721b81c7246dfede887fc1139180e138eb6d945 Mon Sep 17 00:00:00 2001 From: Kyle Carow Date: Fri, 13 Oct 2023 12:09:13 -0600 Subject: [PATCH 1/2] replace map_err with with_context --- rust/fastsim-core/src/simdrive/simdrive_iter.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rust/fastsim-core/src/simdrive/simdrive_iter.rs b/rust/fastsim-core/src/simdrive/simdrive_iter.rs index 737048ce..bd39aba4 100644 --- a/rust/fastsim-core/src/simdrive/simdrive_iter.rs +++ b/rust/fastsim-core/src/simdrive/simdrive_iter.rs @@ -6,6 +6,7 @@ use crate::imports::*; use crate::proc_macros::add_pyo3_api; #[cfg(feature = "pyo3")] use crate::pyo3imports::*; +use anyhow::Context; use rayon::prelude::*; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] @@ -49,12 +50,12 @@ impl SimDriveVec { if parallelize { self.0.par_iter_mut().enumerate().try_for_each(|(i, sd)| { sd.sim_drive(None, None) - .map_err(|err| err.context(format!("simdrive idx:{}", i))) + .with_context(|| format!("simdrive idx: {}", i)) })?; } else { self.0.iter_mut().enumerate().try_for_each(|(i, sd)| { sd.sim_drive(None, None) - .map_err(|err| err.context(format!("simdrive idx:{}", i))) + .with_context(|| format!("simdrive idx: {}", i)) })?; } Ok(()) From d0bbf470454dc55550fea833c216589bc6e932d0 Mon Sep 17 00:00:00 2001 From: Kyle Carow Date: Fri, 13 Oct 2023 12:11:16 -0600 Subject: [PATCH 2/2] add anyhow::Context to imports.rs --- rust/fastsim-core/src/imports.rs | 3 +-- rust/fastsim-core/src/simdrive/simdrive_iter.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/rust/fastsim-core/src/imports.rs b/rust/fastsim-core/src/imports.rs index 3317cf10..a28083f9 100644 --- a/rust/fastsim-core/src/imports.rs +++ b/rust/fastsim-core/src/imports.rs @@ -1,4 +1,4 @@ -pub(crate) use anyhow::{anyhow, bail, ensure}; +pub(crate) use anyhow::{anyhow, bail, ensure, Context}; pub(crate) use bincode::{deserialize, serialize}; pub(crate) use log; pub(crate) use ndarray::{array, concatenate, s, Array, Array1, Axis}; @@ -10,4 +10,3 @@ pub(crate) use std::path::{Path, PathBuf}; pub(crate) use crate::traits::*; pub(crate) use crate::utils::*; - diff --git a/rust/fastsim-core/src/simdrive/simdrive_iter.rs b/rust/fastsim-core/src/simdrive/simdrive_iter.rs index bd39aba4..98c5e88a 100644 --- a/rust/fastsim-core/src/simdrive/simdrive_iter.rs +++ b/rust/fastsim-core/src/simdrive/simdrive_iter.rs @@ -6,7 +6,6 @@ use crate::imports::*; use crate::proc_macros::add_pyo3_api; #[cfg(feature = "pyo3")] use crate::pyo3imports::*; -use anyhow::Context; use rayon::prelude::*; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]