Skip to content

Commit 1404c90

Browse files
committed
Don't require a mutable ref to self in the logical meter methods
There is no reason for them to be mutable anymore. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent 10bc5cd commit 1404c90

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

examples/logical_meter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async fn main() -> Result<(), Error> {
1919
.init();
2020

2121
let client = MicrogridClientHandle::try_new("http://[::1]:8800").await?;
22-
let mut logical_meter = LogicalMeterHandle::try_new(
22+
let logical_meter = LogicalMeterHandle::try_new(
2323
client,
2424
LogicalMeterConfig::new(TimeDelta::try_seconds(1).unwrap()),
2525
)

src/logical_meter/logical_meter_handle.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl LogicalMeterHandle {
6161

6262
/// Returns a receiver that streams samples for the given `metric` at the grid
6363
/// connection point.
64-
pub fn grid<M: metric::Metric>(&mut self) -> Result<Formula<M::QuantityType>, Error> {
64+
pub fn grid<M: metric::Metric>(&self) -> Result<Formula<M::QuantityType>, Error> {
6565
Ok(Formula::Subscriber(Box::new(M::FormulaType::grid(
6666
&self.graph,
6767
self.instructions_tx.clone(),
@@ -73,7 +73,7 @@ impl LogicalMeterHandle {
7373
///
7474
/// When `component_ids` is `None`, all batteries in the microgrid are used.
7575
pub fn battery<M: metric::Metric>(
76-
&mut self,
76+
&self,
7777
component_ids: Option<BTreeSet<u64>>,
7878
) -> Result<Formula<M::QuantityType>, Error> {
7979
Ok(Formula::Subscriber(Box::new(M::FormulaType::battery(
@@ -88,7 +88,7 @@ impl LogicalMeterHandle {
8888
///
8989
/// When `component_ids` is `None`, all CHPs in the microgrid are used.
9090
pub fn chp<M: metric::Metric>(
91-
&mut self,
91+
&self,
9292
component_ids: Option<BTreeSet<u64>>,
9393
) -> Result<Formula<M::QuantityType>, Error> {
9494
Ok(Formula::Subscriber(Box::new(M::FormulaType::chp(
@@ -103,7 +103,7 @@ impl LogicalMeterHandle {
103103
///
104104
/// When `component_ids` is `None`, all PVs in the microgrid are used.
105105
pub fn pv<M: metric::Metric>(
106-
&mut self,
106+
&self,
107107
component_ids: Option<BTreeSet<u64>>,
108108
) -> Result<Formula<M::QuantityType>, Error> {
109109
Ok(Formula::Subscriber(Box::new(M::FormulaType::pv(
@@ -119,7 +119,7 @@ impl LogicalMeterHandle {
119119
/// When `component_ids` is `None`, all EV chargers in the microgrid are
120120
/// used.
121121
pub fn ev_charger<M: metric::Metric>(
122-
&mut self,
122+
&self,
123123
component_ids: Option<BTreeSet<u64>>,
124124
) -> Result<Formula<M::QuantityType>, Error> {
125125
Ok(Formula::Subscriber(Box::new(M::FormulaType::ev_charger(
@@ -131,7 +131,7 @@ impl LogicalMeterHandle {
131131

132132
/// Returns a receiver that streams samples for the given `metric` for the
133133
/// logical `consumer` in the microgrid.
134-
pub fn consumer<M: metric::Metric>(&mut self) -> Result<Formula<M::QuantityType>, Error> {
134+
pub fn consumer<M: metric::Metric>(&self) -> Result<Formula<M::QuantityType>, Error> {
135135
Ok(Formula::Subscriber(Box::new(M::FormulaType::consumer(
136136
&self.graph,
137137
self.instructions_tx.clone(),
@@ -140,7 +140,7 @@ impl LogicalMeterHandle {
140140

141141
/// Returns a receiver that streams samples for the given `metric` for the
142142
/// logical `producer` in the microgrid.
143-
pub fn producer<M: metric::Metric>(&mut self) -> Result<Formula<M::QuantityType>, Error> {
143+
pub fn producer<M: metric::Metric>(&self) -> Result<Formula<M::QuantityType>, Error> {
144144
Ok(Formula::Subscriber(Box::new(M::FormulaType::producer(
145145
&self.graph,
146146
self.instructions_tx.clone(),
@@ -150,7 +150,7 @@ impl LogicalMeterHandle {
150150
/// Returns a receiver that streams samples for the given `metric` for the
151151
/// given component ID.
152152
pub fn component<M: metric::Metric>(
153-
&mut self,
153+
&self,
154154
component_id: u64,
155155
) -> Result<Formula<M::QuantityType>, Error> {
156156
Ok(Formula::Subscriber(Box::new(M::FormulaType::component(
@@ -238,7 +238,7 @@ mod tests {
238238

239239
#[tokio::test]
240240
async fn test_formula_display() {
241-
let mut lm = new_logical_meter_handle(None).await;
241+
let lm = new_logical_meter_handle(None).await;
242242

243243
let formula = lm.grid::<crate::metric::AcPowerActive>().unwrap();
244244
assert_eq!(formula.to_string(), "METRIC_AC_POWER_ACTIVE::(#2)");
@@ -407,7 +407,7 @@ mod tests {
407407
.with_default_resampling_function(ResamplingFunction::Count)
408408
.override_resampling_function::<crate::metric::AcVoltage>(ResamplingFunction::Last),
409409
);
410-
let mut lm = new_logical_meter_handle(lm_config).await;
410+
let lm = new_logical_meter_handle(lm_config).await;
411411
let bat_volt_formula = lm.battery::<crate::metric::AcVoltage>(None).unwrap();
412412

413413
let samples = fetch_samples(bat_volt_formula, 10).await;
@@ -458,7 +458,7 @@ mod tests {
458458
.with_max_age_in_intervals(1)
459459
.with_default_resampling_function(ResamplingFunction::Count),
460460
);
461-
let mut lm = new_logical_meter_handle(lm_config).await;
461+
let lm = new_logical_meter_handle(lm_config).await;
462462
let formula = lm.consumer::<crate::metric::AcPowerActive>().unwrap();
463463

464464
let samples = fetch_samples(formula, 8).await;
@@ -483,7 +483,7 @@ mod tests {
483483
.with_max_age_in_intervals(3)
484484
.with_default_resampling_function(ResamplingFunction::Count),
485485
);
486-
let mut lm = new_logical_meter_handle(lm_config).await;
486+
let lm = new_logical_meter_handle(lm_config).await;
487487
let formula = lm.consumer::<crate::metric::AcPowerActive>().unwrap();
488488

489489
let samples = fetch_samples(formula, 10).await;

0 commit comments

Comments
 (0)