Skip to content

Commit

Permalink
Use references in validate function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmittag committed Jan 30, 2024
1 parent 7b282f8 commit 6f01020
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions kuksa_databroker/databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ impl Entry {
if let Some(datapoint) = &update.datapoint {
self.validate_value(&datapoint.value)?;
self.validate_allowed(&datapoint.value)?;
self.validate_timestamp(datapoint.ts)?;
self.validate_timestamp(&datapoint.ts)?;
}
if let Some(Some(actuatortarget)) = &update.actuator_target {
self.validate_value(&actuatortarget.value)?;
self.validate_allowed(&actuatortarget.value)?;
self.validate_timestamp(actuatortarget.ts)?;
self.validate_timestamp(&actuatortarget.ts)?;
}
if let Some(Some(updated_allowed)) = update.allowed.clone() {
if Some(updated_allowed.clone()) != self.metadata.allowed {
Expand Down Expand Up @@ -558,12 +558,12 @@ impl Entry {
}
}

fn validate_timestamp(&self, timestamp: SystemTime) -> Result<(), UpdateError> {
if self.datapoint.ts > timestamp {
fn validate_timestamp(&self, timestamp: &SystemTime) -> Result<(), UpdateError> {
if self.datapoint.ts > *timestamp {
return Err(UpdateError::TimestampTooOld);
}
if let Some(target) = &self.actuator_target {
if target.ts > timestamp {
if target.ts > *timestamp {
return Err(UpdateError::TimestampTooOld);
}
}
Expand Down Expand Up @@ -1747,7 +1747,6 @@ mod tests {
EntryType::Sensor,
"Test datapoint 1".to_owned(),
None,
None,
)
.await
.expect("Register datapoint should succeed");
Expand All @@ -1760,7 +1759,6 @@ mod tests {
EntryType::Actuator,
"Test datapoint 2".to_owned(),
None,
None,
)
.await
.expect("Register datapoint should succeed");
Expand All @@ -1783,7 +1781,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand All @@ -1803,7 +1800,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand All @@ -1823,7 +1819,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand Down Expand Up @@ -1854,7 +1849,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand Down

0 comments on commit 6f01020

Please sign in to comment.