From bcb3b9896e9b006fc43eaa2bbb9bd7a682b7d148 Mon Sep 17 00:00:00 2001 From: William Lyles <26171886+wilyle@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:43:42 -0700 Subject: [PATCH] clippy + fmt --- .../src/in_memory_mock_cloud_adapter.rs | 1 - .../src/mock_digital_twin_adapter.rs | 4 +- freyja/src/cartographer.rs | 41 ++++++++++---- freyja/src/emitter.rs | 55 +++++++++++-------- 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/cloud_adapters/in_memory_mock_cloud_adapter/src/in_memory_mock_cloud_adapter.rs b/cloud_adapters/in_memory_mock_cloud_adapter/src/in_memory_mock_cloud_adapter.rs index 0e9bd0bd..32240747 100644 --- a/cloud_adapters/in_memory_mock_cloud_adapter/src/in_memory_mock_cloud_adapter.rs +++ b/cloud_adapters/in_memory_mock_cloud_adapter/src/in_memory_mock_cloud_adapter.rs @@ -49,7 +49,6 @@ impl CloudAdapter for InMemoryMockCloudAdapter { /// Creates a new instance of a CloudAdapter with default settings fn create_new() -> Result { Self::from_config_file(Path::new(env!("OUT_DIR")).join(CONFIG_FILE)) - //.map(|r| Box::new(r) as _) } /// Sends the signal to the cloud diff --git a/digital_twin_adapters/mock_digital_twin_adapter/src/mock_digital_twin_adapter.rs b/digital_twin_adapters/mock_digital_twin_adapter/src/mock_digital_twin_adapter.rs index d2992d76..f5ea852f 100644 --- a/digital_twin_adapters/mock_digital_twin_adapter/src/mock_digital_twin_adapter.rs +++ b/digital_twin_adapters/mock_digital_twin_adapter/src/mock_digital_twin_adapter.rs @@ -61,9 +61,7 @@ impl DigitalTwinAdapter for MockDigitalTwinAdapter { let settings: Settings = serde_json::from_str(settings_content.as_str()) .map_err(DigitalTwinAdapterError::deserialize)?; - Ok(Self::with_uri( - &settings.base_uri_for_digital_twin_server, - )) + Ok(Self::with_uri(&settings.base_uri_for_digital_twin_server)) } /// Gets the info of an entity via an HTTP request. diff --git a/freyja/src/cartographer.rs b/freyja/src/cartographer.rs index 0b7adf8a..c1fe6550 100644 --- a/freyja/src/cartographer.rs +++ b/freyja/src/cartographer.rs @@ -10,7 +10,10 @@ use log::{info, warn}; use freyja_contracts::{ conversion::Conversion, - digital_twin_adapter::{DigitalTwinAdapter, GetDigitalTwinProviderRequest, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind}, + digital_twin_adapter::{ + DigitalTwinAdapter, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind, + GetDigitalTwinProviderRequest, + }, mapping_client::{CheckForWorkRequest, GetMappingRequest, MappingClient}, provider_proxy_request::{ ProviderProxySelectorRequestKind, ProviderProxySelectorRequestSender, @@ -36,7 +39,9 @@ pub struct Cartographer { poll_interval: Duration, } -impl Cartographer { +impl + Cartographer +{ /// Create a new instance of a Cartographer /// /// # Arguments @@ -72,7 +77,7 @@ impl Car .mapping_client .check_for_work(CheckForWorkRequest {}) .await; - + if mapping_client_result.is_err() { log::error!("Failed to check for mapping work; will try again later. Error: {mapping_client_result:?}"); continue; @@ -89,7 +94,7 @@ impl Car log::error!("Falied to get mapping from mapping client: {signals_result:?}"); continue; } - + let mut signals = signals_result.unwrap(); let mut failed_signals = Vec::new(); @@ -103,23 +108,37 @@ impl Car let populate_result = self.populate_entity(signal).await; if populate_result.is_err() { - match populate_result.err().unwrap().downcast::() { + match populate_result + .err() + .unwrap() + .downcast::() + { Ok(e) if e.kind() == DigitalTwinAdapterErrorKind::EntityNotFound => { warn!("Entity not found for signal {}", signal.id); - }, + } Ok(e) => { - log::error!("Error fetching entity for signal {}: {e:?}", signal.id); - }, + log::error!( + "Error fetching entity for signal {}: {e:?}", + signal.id + ); + } Err(e) => { - log::error!("Error fetching entity for signal {}: {e:?}", signal.id); - }, + log::error!( + "Error fetching entity for signal {}: {e:?}", + signal.id + ); + } } failed_signals.push(signal.id.clone()); } } - self.signals.sync(signals.into_iter().filter(|s| !failed_signals.contains(&s.id))); + self.signals.sync( + signals + .into_iter() + .filter(|s| !failed_signals.contains(&s.id)), + ); } tokio::time::sleep(self.poll_interval).await; diff --git a/freyja/src/emitter.rs b/freyja/src/emitter.rs index e866aa98..3e00eae6 100644 --- a/freyja/src/emitter.rs +++ b/freyja/src/emitter.rs @@ -95,7 +95,7 @@ impl Emitter { /// Performs data emissions of the provided signals. /// Returns the amount of time that the main emitter loop should sleep before the next iteration. - /// + /// /// # Arguments /// - `signals`: The set of signals to emit async fn emit_data(&self, signals: Vec) -> Result { @@ -125,7 +125,8 @@ impl Emitter { entity_id: signal.id.clone(), }; - let proxy_result = self.provider_proxy_selector_client + let proxy_result = self + .provider_proxy_selector_client .send_request_to_provider_proxy_selector(request) .map_err(EmitterError::provider_proxy_error); @@ -157,7 +158,11 @@ impl Emitter { let send_to_cloud_result = self.send_to_cloud(signal).await; if send_to_cloud_result.is_err() { - log::error!("Error sending data to cloud while processing signal {}: {:?}", signal_id, send_to_cloud_result.err()); + log::error!( + "Error sending data to cloud while processing signal {}: {:?}", + signal_id, + send_to_cloud_result.err() + ); } } @@ -221,7 +226,10 @@ proc_macros::error! { mod emitter_tests { use super::*; use async_trait::async_trait; - use freyja_contracts::{cloud_adapter::{CloudAdapterError, CloudAdapterErrorKind}, signal::{Emission, EmissionPolicy}}; + use freyja_contracts::{ + cloud_adapter::{CloudAdapterError, CloudAdapterErrorKind}, + signal::{Emission, EmissionPolicy}, + }; use mockall::*; use tokio::sync::mpsc; @@ -267,8 +275,7 @@ mod emitter_tests { let listener_handler = tokio::spawn(async move { rx.recv().await }); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() - .never(); + mock_cloud_adapter.expect_send_to_cloud().never(); let mut uut = Emitter { signals: Arc::new(SignalStore::new()), @@ -313,9 +320,10 @@ mod emitter_tests { let listener_handler = tokio::spawn(async move { rx.recv().await }); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() + mock_cloud_adapter + .expect_send_to_cloud() .once() - .returning(|_| Ok(CloudMessageResponse { })); + .returning(|_| Ok(CloudMessageResponse {})); let mut uut = Emitter { signals: Arc::new(SignalStore::new()), @@ -358,8 +366,7 @@ mod emitter_tests { let listener_handler = tokio::spawn(async move { rx.recv().await }); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() - .never(); + mock_cloud_adapter.expect_send_to_cloud().never(); let mut uut = Emitter { signals: Arc::new(SignalStore::new()), @@ -402,8 +409,7 @@ mod emitter_tests { let listener_handler = tokio::spawn(async move { rx.recv().await }); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() - .never(); + mock_cloud_adapter.expect_send_to_cloud().never(); let mut uut = Emitter { signals: Arc::new(SignalStore::new()), @@ -423,7 +429,6 @@ mod emitter_tests { emit_only_if_changed: true, ..Default::default() }, - ..Default::default() }, ..Default::default() }; @@ -449,9 +454,10 @@ mod emitter_tests { let listener_handler = tokio::spawn(async move { rx.recv().await }); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() + mock_cloud_adapter + .expect_send_to_cloud() .once() - .returning(|_| Ok(CloudMessageResponse { })); + .returning(|_| Ok(CloudMessageResponse {})); let mut uut = Emitter { signals: Arc::new(SignalStore::new()), @@ -470,7 +476,6 @@ mod emitter_tests { emit_only_if_changed: true, ..Default::default() }, - ..Default::default() }, ..Default::default() }; @@ -496,9 +501,10 @@ mod emitter_tests { let listener_handler = tokio::spawn(async move { rx.recv().await }); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() + mock_cloud_adapter + .expect_send_to_cloud() .once() - .returning(|_| Ok(CloudMessageResponse { })); + .returning(|_| Ok(CloudMessageResponse {})); let mut uut = Emitter { signals: Arc::new(SignalStore::new()), @@ -517,7 +523,6 @@ mod emitter_tests { emit_only_if_changed: true, ..Default::default() }, - ..Default::default() }, ..Default::default() }; @@ -540,7 +545,8 @@ mod emitter_tests { let provider_proxy_selector_client = ProviderProxySelectorRequestSender::new(tx); let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() + mock_cloud_adapter + .expect_send_to_cloud() .times(2) .returning(|_| Err(CloudAdapterErrorKind::Unknown.into())); @@ -570,10 +576,11 @@ mod emitter_tests { let (tx, _) = mpsc::unbounded_channel::(); let provider_proxy_selector_client = ProviderProxySelectorRequestSender::new(tx); - + let mut mock_cloud_adapter = MockCloudAdapterImpl::new(); - mock_cloud_adapter.expect_send_to_cloud() - .returning(|_| Ok(CloudMessageResponse { })); + mock_cloud_adapter + .expect_send_to_cloud() + .returning(|_| Ok(CloudMessageResponse {})); let test_signal = Signal { id: ID.to_string(), @@ -609,4 +616,4 @@ mod emitter_tests { assert!(signal.emission.last_emitted_value.is_some()); assert_eq!(signal.emission.next_emission_ms, INTERVAL); } -} \ No newline at end of file +}