diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d3ae3c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**target/ diff --git a/overwatch-rs/src/overwatch/handle.rs b/overwatch-rs/src/overwatch/handle.rs index f4213ef..ee5dcae 100644 --- a/overwatch-rs/src/overwatch/handle.rs +++ b/overwatch-rs/src/overwatch/handle.rs @@ -34,7 +34,7 @@ impl OverwatchHandle { } /// Send a shutdown signal to the overwatch runner - pub async fn shutdown(&mut self) { + pub async fn shutdown(&self) { info!("Shutting down Overwatch"); if let Err(e) = self .sender @@ -48,7 +48,7 @@ impl OverwatchHandle { } /// Send a kill signal to the overwatch runner - pub async fn kill(&mut self) { + pub async fn kill(&self) { info!("Killing Overwatch"); if let Err(e) = self .sender @@ -63,14 +63,14 @@ impl OverwatchHandle { /// Send an overwatch command to the overwatch runner #[instrument(name = "overwatch-command-send", skip(self))] - pub async fn send(&mut self, command: OverwatchCommand) { + pub async fn send(&self, command: OverwatchCommand) { if let Err(e) = self.sender.send(command).await { error!(error=?e, "Error sending overwatch command"); } } #[instrument(skip(self))] - pub async fn update_settings(&mut self, settings: S::Settings) { + pub async fn update_settings(&self, settings: S::Settings) { if let Err(e) = self .sender .send(OverwatchCommand::Settings(SettingsCommand(Box::new( diff --git a/overwatch-rs/src/overwatch/mod.rs b/overwatch-rs/src/overwatch/mod.rs index c416d0f..492a3ae 100644 --- a/overwatch-rs/src/overwatch/mod.rs +++ b/overwatch-rs/src/overwatch/mod.rs @@ -265,7 +265,7 @@ mod test { #[test] fn run_overwatch_then_stop() { let overwatch = OverwatchRunner::::run((), None); - let mut handle = overwatch.handle().clone(); + let handle = overwatch.handle().clone(); overwatch.spawn(async move { sleep(Duration::from_millis(500)).await; @@ -278,7 +278,7 @@ mod test { #[test] fn run_overwatch_then_kill() { let overwatch = OverwatchRunner::::run((), None); - let mut handle = overwatch.handle().clone(); + let handle = overwatch.handle().clone(); overwatch.spawn(async move { sleep(Duration::from_millis(500)).await; diff --git a/overwatch-rs/src/services/handle.rs b/overwatch-rs/src/services/handle.rs index ab3e3cd..e490a30 100644 --- a/overwatch-rs/src/services/handle.rs +++ b/overwatch-rs/src/services/handle.rs @@ -1,5 +1,3 @@ -// std -use std::marker::PhantomData; // crates use futures::future::{abortable, AbortHandle}; use tokio::runtime::Handle; @@ -25,7 +23,6 @@ pub struct ServiceHandle { overwatch_handle: OverwatchHandle, settings: SettingsUpdater, initial_state: S::State, - _marker: PhantomData, } /// Service core resources @@ -58,7 +55,6 @@ impl ServiceHandle { settings, initial_state, overwatch_handle, - _marker: PhantomData::default(), } } diff --git a/overwatch-rs/src/services/relay.rs b/overwatch-rs/src/services/relay.rs index 87fefd0..a23e94d 100644 --- a/overwatch-rs/src/services/relay.rs +++ b/overwatch-rs/src/services/relay.rs @@ -141,13 +141,13 @@ impl Relay { } #[instrument(skip(self), err(Debug))] - pub async fn connect(&mut self) -> Result, RelayError> { + pub async fn connect(&self) -> Result, RelayError> { let (reply, receiver) = oneshot::channel(); self.request_relay(reply).await; self.handle_relay_response(receiver).await } - async fn request_relay(&mut self, reply: oneshot::Sender) { + async fn request_relay(&self, reply: oneshot::Sender) { let relay_command = OverwatchCommand::Relay(RelayCommand { service_id: S::SERVICE_ID, reply_channel: ReplyChannel(reply), @@ -157,7 +157,7 @@ impl Relay { #[instrument(skip_all, err(Debug))] async fn handle_relay_response( - &mut self, + &self, receiver: oneshot::Receiver, ) -> Result, RelayError> { let response = receiver.await; diff --git a/overwatch-rs/src/services/settings.rs b/overwatch-rs/src/services/settings.rs index 0cf6a85..0644ac0 100644 --- a/overwatch-rs/src/services/settings.rs +++ b/overwatch-rs/src/services/settings.rs @@ -22,7 +22,7 @@ impl SettingsNotifier { // of the method. Another option would be to spawn a task that updates a settings local value // each time an updated settings is received. This could not be so easy to do, since it will // need to hold a &mut to the holder (or needed to use a Cell/RefCell). - pub fn get_updated_settings(&mut self) -> S { + pub fn get_updated_settings(&self) -> S { self.notifier_channel.borrow().clone() } } @@ -67,7 +67,7 @@ mod test { #[tokio::test] async fn settings_updater_sequence() { let updater = SettingsUpdater::new(10usize); - let mut notifier = updater.notifier(); + let notifier = updater.notifier(); let values = [10, 0usize]; let mut seq = HashSet::from(values); let handle = tokio::spawn(timeout(Duration::from_secs(3), async move { diff --git a/overwatch-rs/src/services/state.rs b/overwatch-rs/src/services/state.rs index 5c9e7ab..385c151 100644 --- a/overwatch-rs/src/services/state.rs +++ b/overwatch-rs/src/services/state.rs @@ -127,7 +127,7 @@ impl Clone for StateWatcher { impl StateUpdater { /// Send a new state and notify the [`StateWatcher`] - pub fn update(&mut self, new_state: S) { + pub fn update(&self, new_state: S) { self.sender.send(new_state).unwrap_or_else(|_e| { error!("Error updating state"); }); @@ -227,7 +227,7 @@ mod test { #[tokio::test] #[should_panic] async fn state_stream_collects() { - let (handle, mut updater): ( + let (handle, updater): ( StateHandle, StateUpdater, ) = StateHandle::new( diff --git a/overwatch-rs/tests/print_service.rs b/overwatch-rs/tests/print_service.rs index e21f1e2..3616241 100644 --- a/overwatch-rs/tests/print_service.rs +++ b/overwatch-rs/tests/print_service.rs @@ -86,8 +86,8 @@ struct TestApp { fn derive_print_service() { let settings: TestAppServiceSettings = TestAppServiceSettings { print_service: () }; let overwatch = OverwatchRunner::::run(settings, None); - let mut handle = overwatch.handle().clone(); - let mut print_service_relay = handle.relay::(); + let handle = overwatch.handle().clone(); + let print_service_relay = handle.relay::(); overwatch.spawn(async move { let print_service_relay = print_service_relay diff --git a/overwatch-rs/tests/settings_update.rs b/overwatch-rs/tests/settings_update.rs index 6c195dd..209ed9f 100644 --- a/overwatch-rs/tests/settings_update.rs +++ b/overwatch-rs/tests/settings_update.rs @@ -35,11 +35,9 @@ impl ServiceCore for SettingsService { async fn run(mut self) { let Self { - state: - ServiceStateHandle { - mut settings_reader, - .. - }, + state: ServiceStateHandle { + settings_reader, .. + }, } = self; let print = async move { @@ -72,7 +70,7 @@ fn settings_service_update_settings() { }; let overwatch = OverwatchRunner::::run(settings.clone(), None); let handle = overwatch.handle().clone(); - let mut handle2 = handle.clone(); + let handle2 = handle.clone(); settings.settings_service = "New settings".to_string(); overwatch.spawn(async move { handle.clone().update_settings::(settings).await }); diff --git a/overwatch-rs/tests/state_handling.rs b/overwatch-rs/tests/state_handling.rs index 26db4b1..0bb0e6c 100644 --- a/overwatch-rs/tests/state_handling.rs +++ b/overwatch-rs/tests/state_handling.rs @@ -69,9 +69,7 @@ impl ServiceCore for UpdateStateService { async fn run(mut self) { let Self { - state: ServiceStateHandle { - mut state_updater, .. - }, + state: ServiceStateHandle { state_updater, .. }, } = self; for value in 0..10 { state_updater.update(CounterState { value }); @@ -91,7 +89,7 @@ fn state_update_service() { update_state_service: (), }; let overwatch = OverwatchRunner::::run(settings, None); - let mut handle = overwatch.handle().clone(); + let handle = overwatch.handle().clone(); overwatch.spawn(async move { sleep(Duration::from_secs(1)).await;