diff --git a/lighthouse-client/examples/admin_crud.rs b/lighthouse-client/examples/admin_crud.rs index 6831dfc..4b5928d 100644 --- a/lighthouse-client/examples/admin_crud.rs +++ b/lighthouse-client/examples/admin_crud.rs @@ -2,7 +2,7 @@ use clap::Parser; use lighthouse_client::{protocol::Authentication, Error, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL}; use tracing::{info, info_span, Instrument}; -async fn run(mut lh: Lighthouse) -> Result<()> { +async fn run(lh: Lighthouse) -> Result<()> { info!("Connected to the Lighthouse server"); async { diff --git a/lighthouse-client/examples/admin_get_metrics.rs b/lighthouse-client/examples/admin_get_metrics.rs index bba50ff..e3acda6 100644 --- a/lighthouse-client/examples/admin_get_metrics.rs +++ b/lighthouse-client/examples/admin_get_metrics.rs @@ -2,7 +2,7 @@ use clap::Parser; use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL}; use tracing::info; -async fn run(mut lh: Lighthouse) -> Result<()> { +async fn run(lh: Lighthouse) -> Result<()> { info!("Connected to the Lighthouse server"); let metrics = lh.get_laser_metrics().await?.payload; diff --git a/lighthouse-client/examples/admin_list_root.rs b/lighthouse-client/examples/admin_list_root.rs index 6031cc8..bf24aa2 100644 --- a/lighthouse-client/examples/admin_list_root.rs +++ b/lighthouse-client/examples/admin_list_root.rs @@ -2,7 +2,7 @@ use clap::Parser; use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL}; use tracing::info; -async fn run(mut lh: Lighthouse) -> Result<()> { +async fn run(lh: Lighthouse) -> Result<()> { info!("Connected to the Lighthouse server"); let tree = lh.list(&[]).await?.payload; diff --git a/lighthouse-client/examples/black.rs b/lighthouse-client/examples/black.rs index 8c9cf0c..fd16b21 100644 --- a/lighthouse-client/examples/black.rs +++ b/lighthouse-client/examples/black.rs @@ -2,7 +2,7 @@ use clap::Parser; use lighthouse_client::{protocol::{Authentication, Color, Frame}, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL}; use tracing::info; -async fn run(mut lh: Lighthouse) -> Result<()> { +async fn run(lh: Lighthouse) -> Result<()> { info!("Connected to the Lighthouse server"); lh.put_model(Frame::fill(Color::BLACK)).await?; diff --git a/lighthouse-client/examples/disco.rs b/lighthouse-client/examples/disco.rs index 5872b62..eb01e76 100644 --- a/lighthouse-client/examples/disco.rs +++ b/lighthouse-client/examples/disco.rs @@ -4,7 +4,7 @@ use tracing::info; use tokio::time; use std::time::Duration; -async fn run(mut lh: Lighthouse) -> Result<()> { +async fn run(lh: Lighthouse) -> Result<()> { info!("Connected to the Lighthouse server"); loop { diff --git a/lighthouse-client/examples/input_events.rs b/lighthouse-client/examples/input_events.rs index 3425709..52720a8 100644 --- a/lighthouse-client/examples/input_events.rs +++ b/lighthouse-client/examples/input_events.rs @@ -4,7 +4,7 @@ use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSo use lighthouse_protocol::Model; use tracing::info; -async fn run(mut lh: Lighthouse) -> Result<()> { +async fn run(lh: Lighthouse) -> Result<()> { info!("Connected to the Lighthouse server"); // Stream input events diff --git a/lighthouse-client/examples/snake.rs b/lighthouse-client/examples/snake.rs index 08078a2..81b3d7f 100644 --- a/lighthouse-client/examples/snake.rs +++ b/lighthouse-client/examples/snake.rs @@ -124,7 +124,7 @@ impl State { } } -async fn run_updater(mut lh: Lighthouse, shared_state: Arc>) -> Result<()> { +async fn run_updater(lh: Lighthouse, shared_state: Arc>) -> Result<()> { loop { // Update the snake and render it let frame = { @@ -190,7 +190,7 @@ async fn main() -> Result<()> { let auth = Authentication::new(&args.username, &args.token); let state = Arc::new(Mutex::new(State::new())); - let mut lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?; + let lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?; info!("Connected to the Lighthouse server"); let stream = lh.stream_model().await?; diff --git a/lighthouse-client/examples/stress_test.rs b/lighthouse-client/examples/stress_test.rs index df545d8..a5f95d5 100644 --- a/lighthouse-client/examples/stress_test.rs +++ b/lighthouse-client/examples/stress_test.rs @@ -5,7 +5,7 @@ use lighthouse_client::{protocol::{Authentication, Frame}, Lighthouse, Result, T use tokio::time::{self, Instant}; use tracing::info; -async fn run(mut lh: Lighthouse, delay_ms: Option) -> Result<()> { +async fn run(lh: Lighthouse, delay_ms: Option) -> Result<()> { info!("Connected to the Lighthouse server"); let mut last_second = Instant::now(); diff --git a/lighthouse-client/src/lighthouse.rs b/lighthouse-client/src/lighthouse.rs index 42d7f5b..0a68271 100644 --- a/lighthouse-client/src/lighthouse.rs +++ b/lighthouse-client/src/lighthouse.rs @@ -116,81 +116,81 @@ impl Lighthouse } /// Replaces the user's lighthouse model with the given frame. - pub async fn put_model(&mut self, frame: Frame) -> Result> { + pub async fn put_model(&self, frame: Frame) -> Result> { let username = self.authentication.username.clone(); self.put(&["user", username.as_str(), "model"], Model::Frame(frame)).await } /// Requests a stream of events (including key/controller events) for the user's lighthouse model. - pub async fn stream_model(&mut self) -> Result>>> { + pub async fn stream_model(&self) -> Result>>> { let username = self.authentication.username.clone(); self.stream(&["user", username.as_str(), "model"], ()).await } /// Fetches lamp server metrics. - pub async fn get_laser_metrics(&mut self) -> Result> { + pub async fn get_laser_metrics(&self) -> Result> { self.get(&["metrics", "laser"]).await } /// Combines PUT and CREATE. Requires CREATE and WRITE permission. - pub async fn post

(&mut self, path: &[&str], payload: P) -> Result> + pub async fn post

(&self, path: &[&str], payload: P) -> Result> where P: Serialize { self.perform(&Verb::Post, path, payload).await } /// Updates the resource at the given path with the given payload. Requires WRITE permission. - pub async fn put

(&mut self, path: &[&str], payload: P) -> Result> + pub async fn put

(&self, path: &[&str], payload: P) -> Result> where P: Serialize { self.perform(&Verb::Put, path, payload).await } /// Creates a resource at the given path. Requires CREATE permission. - pub async fn create(&mut self, path: &[&str]) -> Result> { + pub async fn create(&self, path: &[&str]) -> Result> { self.perform(&Verb::Create, path, ()).await } /// Deletes a resource at the given path. Requires DELETE permission. - pub async fn delete(&mut self, path: &[&str]) -> Result> { + pub async fn delete(&self, path: &[&str]) -> Result> { self.perform(&Verb::Delete, path, ()).await } /// Creates a directory at the given path. Requires CREATE permission. - pub async fn mkdir(&mut self, path: &[&str]) -> Result> { + pub async fn mkdir(&self, path: &[&str]) -> Result> { self.perform(&Verb::Mkdir, path, ()).await } /// Lists the directory tree at the given path. Requires READ permission. - pub async fn list(&mut self, path: &[&str]) -> Result> { + pub async fn list(&self, path: &[&str]) -> Result> { self.perform(&Verb::List, path, ()).await } /// Gets the resource at the given path. Requires READ permission. - pub async fn get(&mut self, path: &[&str]) -> Result> + pub async fn get(&self, path: &[&str]) -> Result> where R: for<'de> Deserialize<'de> { self.perform(&Verb::Get, path, ()).await } /// Links the given source to the given destination path. - pub async fn link(&mut self, src_path: &[&str], dest_path: &[&str]) -> Result> { + pub async fn link(&self, src_path: &[&str], dest_path: &[&str]) -> Result> { self.perform(&Verb::Link, dest_path, src_path).await } /// Unlinks the given source from the given destination path. - pub async fn unlink(&mut self, src_path: &[&str], dest_path: &[&str]) -> Result> { + pub async fn unlink(&self, src_path: &[&str], dest_path: &[&str]) -> Result> { self.perform(&Verb::Unlink, dest_path, src_path).await } /// Stops the given stream. - pub async fn stop(&mut self, path: &[&str]) -> Result> { + pub async fn stop(&self, path: &[&str]) -> Result> { self.perform(&Verb::Stop, path, ()).await } /// Performs a single request to the given path with the given payload. #[tracing::instrument(skip(self, payload))] - pub async fn perform(&mut self, verb: &Verb, path: &[&str], payload: P) -> Result> + pub async fn perform(&self, verb: &Verb, path: &[&str], payload: P) -> Result> where P: Serialize, R: for<'de> Deserialize<'de> { @@ -202,7 +202,7 @@ impl Lighthouse /// Performs a STREAM request to the given path with the given payload. #[tracing::instrument(skip(self, payload))] - pub async fn stream(&mut self, path: &[&str], payload: P) -> Result>>> + pub async fn stream(&self, path: &[&str], payload: P) -> Result>>> where P: Serialize, R: for<'de> Deserialize<'de> { @@ -213,7 +213,7 @@ impl Lighthouse } /// Sends a request to the given path with the given payload. - async fn send_request

(&mut self, verb: &Verb, path: &[&str], payload: P) -> Result + async fn send_request

(&self, verb: &Verb, path: &[&str], payload: P) -> Result where P: Serialize { let path = path.into_iter().map(|s| s.to_string()).collect(); @@ -231,7 +231,7 @@ impl Lighthouse } /// Sends a generic message to the lighthouse. - async fn send_message

(&mut self, message: &ClientMessage

) -> Result<()> + async fn send_message

(&self, message: &ClientMessage

) -> Result<()> where P: Serialize { self.send_raw(rmp_serde::to_vec_named(message)?).await @@ -287,7 +287,7 @@ impl Lighthouse } /// Sends raw bytes to the lighthouse via the WebSocket connection. - async fn send_raw(&mut self, bytes: impl Into> + Debug) -> Result<()> { + async fn send_raw(&self, bytes: impl Into> + Debug) -> Result<()> { Ok(self.ws_sink.lock().await.send(Message::Binary(bytes.into())).await?) }