Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

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 14217d8 commit fdc61db
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 @@ -204,12 +204,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 @@ -561,12 +561,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 @@ -1768,7 +1768,6 @@ mod tests {
EntryType::Sensor,
"Test datapoint 1".to_owned(),
None,
None,
)
.await
.expect("Register datapoint should succeed");
Expand All @@ -1781,7 +1780,6 @@ mod tests {
EntryType::Actuator,
"Test datapoint 2".to_owned(),
None,
None,
)
.await
.expect("Register datapoint should succeed");
Expand All @@ -1804,7 +1802,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand All @@ -1824,7 +1821,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand All @@ -1844,7 +1840,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand Down Expand Up @@ -1875,7 +1870,6 @@ mod tests {
data_type: None,
description: None,
allowed: None,
unit: None,
},
)])
.await
Expand Down

0 comments on commit fdc61db

Please sign in to comment.