Skip to content

Commit e05cacf

Browse files
committed
derive Copy for TrackedState<T>, eliminating need to explicitly call .clone() where T: Copy
1 parent 6a3e17a commit e05cacf

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

fastsim-core/src/simdrive/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,10 @@ impl SimDrive {
155155
))
156156
})?;
157157
// final SOC, to use as starting SOC for next iteration (if needed)
158-
let soc_final = self
159-
.veh
160-
.res()
161-
.with_context(|| format_dbg!())?
162-
.state
163-
.soc
164-
.clone();
158+
let soc_final = self.veh.res().with_context(|| format_dbg!())?.state.soc;
165159
// current iteration number, to use as counter for next iteration (if needed)
166-
let soc_bal_iters = self
167-
.veh
168-
.hev()
169-
.with_context(|| format_dbg!())?
170-
.soc_bal_iters
171-
.clone();
160+
let soc_bal_iters =
161+
self.veh.hev().with_context(|| format_dbg!())?.soc_bal_iters;
172162
let res_per_fuel = *self
173163
.veh
174164
.res()

fastsim-core/src/utils/tracked_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
}
3636

3737
/// Enum for tracking mutation
38-
#[derive(Clone, Default, Debug, PartialEq, IsVariant, derive_more::From, TryInto)]
38+
#[derive(Clone, Copy, Default, Debug, PartialEq, IsVariant, derive_more::From, TryInto)]
3939
pub enum StateStatus {
4040
/// Updated in this time step
4141
#[default]
@@ -44,7 +44,7 @@ pub enum StateStatus {
4444
Stale,
4545
}
4646

47-
#[derive(Default, PartialEq, Clone, Debug)]
47+
#[derive(Default, PartialEq, Clone, Copy, Debug)]
4848
/// Struct for storing state variable and ensuring one mutation per
4949
/// initialization or reset -- i.e. one mutation per time step
5050
pub struct TrackedState<T>(

0 commit comments

Comments
 (0)