Skip to content

Commit 49e616c

Browse files
committed
Remove mutability requirement from Lighthouse
1 parent 7b13a8b commit 49e616c

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

lighthouse-client/examples/admin_crud.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::Parser;
22
use lighthouse_client::{protocol::Authentication, Error, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
33
use tracing::{info, info_span, Instrument};
44

5-
async fn run(mut lh: Lighthouse<TokioWebSocket>) -> Result<()> {
5+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
66
info!("Connected to the Lighthouse server");
77

88
async {

lighthouse-client/examples/admin_get_metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::Parser;
22
use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
33
use tracing::info;
44

5-
async fn run(mut lh: Lighthouse<TokioWebSocket>) -> Result<()> {
5+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
66
info!("Connected to the Lighthouse server");
77

88
let metrics = lh.get_laser_metrics().await?.payload;

lighthouse-client/examples/admin_list_root.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::Parser;
22
use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
33
use tracing::info;
44

5-
async fn run(mut lh: Lighthouse<TokioWebSocket>) -> Result<()> {
5+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
66
info!("Connected to the Lighthouse server");
77

88
let tree = lh.list(&[]).await?.payload;

lighthouse-client/examples/black.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::Parser;
22
use lighthouse_client::{protocol::{Authentication, Color, Frame}, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
33
use tracing::info;
44

5-
async fn run(mut lh: Lighthouse<TokioWebSocket>) -> Result<()> {
5+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
66
info!("Connected to the Lighthouse server");
77

88
lh.put_model(Frame::fill(Color::BLACK)).await?;

lighthouse-client/examples/disco.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tracing::info;
44
use tokio::time;
55
use std::time::Duration;
66

7-
async fn run(mut lh: Lighthouse<TokioWebSocket>) -> Result<()> {
7+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
88
info!("Connected to the Lighthouse server");
99

1010
loop {

lighthouse-client/examples/input_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSo
44
use lighthouse_protocol::Model;
55
use tracing::info;
66

7-
async fn run(mut lh: Lighthouse<TokioWebSocket>) -> Result<()> {
7+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
88
info!("Connected to the Lighthouse server");
99

1010
// Stream input events

lighthouse-client/examples/snake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl State {
124124
}
125125
}
126126

127-
async fn run_updater(mut lh: Lighthouse<TokioWebSocket>, shared_state: Arc<Mutex<State>>) -> Result<()> {
127+
async fn run_updater(lh: Lighthouse<TokioWebSocket>, shared_state: Arc<Mutex<State>>) -> Result<()> {
128128
loop {
129129
// Update the snake and render it
130130
let frame = {
@@ -190,7 +190,7 @@ async fn main() -> Result<()> {
190190
let auth = Authentication::new(&args.username, &args.token);
191191
let state = Arc::new(Mutex::new(State::new()));
192192

193-
let mut lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?;
193+
let lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?;
194194
info!("Connected to the Lighthouse server");
195195

196196
let stream = lh.stream_model().await?;

lighthouse-client/examples/stress_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use lighthouse_client::{protocol::{Authentication, Frame}, Lighthouse, Result, T
55
use tokio::time::{self, Instant};
66
use tracing::info;
77

8-
async fn run(mut lh: Lighthouse<TokioWebSocket>, delay_ms: Option<u64>) -> Result<()> {
8+
async fn run(lh: Lighthouse<TokioWebSocket>, delay_ms: Option<u64>) -> Result<()> {
99
info!("Connected to the Lighthouse server");
1010

1111
let mut last_second = Instant::now();

lighthouse-client/src/lighthouse.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,81 +120,81 @@ impl<S> Lighthouse<S>
120120
}
121121

122122
/// Replaces the user's lighthouse model with the given frame.
123-
pub async fn put_model(&mut self, frame: Frame) -> Result<ServerMessage<()>> {
123+
pub async fn put_model(&self, frame: Frame) -> Result<ServerMessage<()>> {
124124
let username = self.authentication.username.clone();
125125
self.put(&["user", username.as_str(), "model"], Model::Frame(frame)).await
126126
}
127127

128128
/// Requests a stream of events (including key/controller events) for the user's lighthouse model.
129-
pub async fn stream_model(&mut self) -> Result<impl Stream<Item = Result<ServerMessage<Model>>>> {
129+
pub async fn stream_model(&self) -> Result<impl Stream<Item = Result<ServerMessage<Model>>>> {
130130
let username = self.authentication.username.clone();
131131
self.stream(&["user", username.as_str(), "model"], ()).await
132132
}
133133

134134
/// Fetches lamp server metrics.
135-
pub async fn get_laser_metrics(&mut self) -> Result<ServerMessage<LaserMetrics>> {
135+
pub async fn get_laser_metrics(&self) -> Result<ServerMessage<LaserMetrics>> {
136136
self.get(&["metrics", "laser"]).await
137137
}
138138

139139
/// Combines PUT and CREATE. Requires CREATE and WRITE permission.
140-
pub async fn post<P>(&mut self, path: &[&str], payload: P) -> Result<ServerMessage<()>>
140+
pub async fn post<P>(&self, path: &[&str], payload: P) -> Result<ServerMessage<()>>
141141
where
142142
P: Serialize {
143143
self.perform(&Verb::Post, path, payload).await
144144
}
145145

146146
/// Updates the resource at the given path with the given payload. Requires WRITE permission.
147-
pub async fn put<P>(&mut self, path: &[&str], payload: P) -> Result<ServerMessage<()>>
147+
pub async fn put<P>(&self, path: &[&str], payload: P) -> Result<ServerMessage<()>>
148148
where
149149
P: Serialize {
150150
self.perform(&Verb::Put, path, payload).await
151151
}
152152

153153
/// Creates a resource at the given path. Requires CREATE permission.
154-
pub async fn create(&mut self, path: &[&str]) -> Result<ServerMessage<()>> {
154+
pub async fn create(&self, path: &[&str]) -> Result<ServerMessage<()>> {
155155
self.perform(&Verb::Create, path, ()).await
156156
}
157157

158158
/// Deletes a resource at the given path. Requires DELETE permission.
159-
pub async fn delete(&mut self, path: &[&str]) -> Result<ServerMessage<()>> {
159+
pub async fn delete(&self, path: &[&str]) -> Result<ServerMessage<()>> {
160160
self.perform(&Verb::Delete, path, ()).await
161161
}
162162

163163
/// Creates a directory at the given path. Requires CREATE permission.
164-
pub async fn mkdir(&mut self, path: &[&str]) -> Result<ServerMessage<()>> {
164+
pub async fn mkdir(&self, path: &[&str]) -> Result<ServerMessage<()>> {
165165
self.perform(&Verb::Mkdir, path, ()).await
166166
}
167167

168168
/// Lists the directory tree at the given path. Requires READ permission.
169-
pub async fn list(&mut self, path: &[&str]) -> Result<ServerMessage<DirectoryTree>> {
169+
pub async fn list(&self, path: &[&str]) -> Result<ServerMessage<DirectoryTree>> {
170170
self.perform(&Verb::List, path, ()).await
171171
}
172172

173173
/// Gets the resource at the given path. Requires READ permission.
174-
pub async fn get<R>(&mut self, path: &[&str]) -> Result<ServerMessage<R>>
174+
pub async fn get<R>(&self, path: &[&str]) -> Result<ServerMessage<R>>
175175
where
176176
R: for<'de> Deserialize<'de> {
177177
self.perform(&Verb::Get, path, ()).await
178178
}
179179

180180
/// Links the given source to the given destination path.
181-
pub async fn link(&mut self, src_path: &[&str], dest_path: &[&str]) -> Result<ServerMessage<()>> {
181+
pub async fn link(&self, src_path: &[&str], dest_path: &[&str]) -> Result<ServerMessage<()>> {
182182
self.perform(&Verb::Link, dest_path, src_path).await
183183
}
184184

185185
/// Unlinks the given source from the given destination path.
186-
pub async fn unlink(&mut self, src_path: &[&str], dest_path: &[&str]) -> Result<ServerMessage<()>> {
186+
pub async fn unlink(&self, src_path: &[&str], dest_path: &[&str]) -> Result<ServerMessage<()>> {
187187
self.perform(&Verb::Unlink, dest_path, src_path).await
188188
}
189189

190190
/// Stops the given stream.
191-
pub async fn stop(&mut self, path: &[&str]) -> Result<ServerMessage<()>> {
191+
pub async fn stop(&self, path: &[&str]) -> Result<ServerMessage<()>> {
192192
self.perform(&Verb::Stop, path, ()).await
193193
}
194194

195195
/// Performs a single request to the given path with the given payload.
196196
#[tracing::instrument(skip(self, payload))]
197-
pub async fn perform<P, R>(&mut self, verb: &Verb, path: &[&str], payload: P) -> Result<ServerMessage<R>>
197+
pub async fn perform<P, R>(&self, verb: &Verb, path: &[&str], payload: P) -> Result<ServerMessage<R>>
198198
where
199199
P: Serialize,
200200
R: for<'de> Deserialize<'de> {
@@ -206,7 +206,7 @@ impl<S> Lighthouse<S>
206206

207207
/// Performs a STREAM request to the given path with the given payload.
208208
#[tracing::instrument(skip(self, payload))]
209-
pub async fn stream<P, R>(&mut self, path: &[&str], payload: P) -> Result<impl Stream<Item = Result<ServerMessage<R>>>>
209+
pub async fn stream<P, R>(&self, path: &[&str], payload: P) -> Result<impl Stream<Item = Result<ServerMessage<R>>>>
210210
where
211211
P: Serialize,
212212
R: for<'de> Deserialize<'de> {
@@ -217,7 +217,7 @@ impl<S> Lighthouse<S>
217217
}
218218

219219
/// Sends a request to the given path with the given payload.
220-
async fn send_request<P>(&mut self, verb: &Verb, path: &[&str], payload: P) -> Result<i32>
220+
async fn send_request<P>(&self, verb: &Verb, path: &[&str], payload: P) -> Result<i32>
221221
where
222222
P: Serialize {
223223
let path = path.into_iter().map(|s| s.to_string()).collect();
@@ -235,7 +235,7 @@ impl<S> Lighthouse<S>
235235
}
236236

237237
/// Sends a generic message to the lighthouse.
238-
async fn send_message<P>(&mut self, message: &ClientMessage<P>) -> Result<()>
238+
async fn send_message<P>(&self, message: &ClientMessage<P>) -> Result<()>
239239
where
240240
P: Serialize {
241241
self.send_raw(rmp_serde::to_vec_named(message)?).await
@@ -291,7 +291,7 @@ impl<S> Lighthouse<S>
291291
}
292292

293293
/// Sends raw bytes to the lighthouse via the WebSocket connection.
294-
async fn send_raw(&mut self, bytes: impl Into<Vec<u8>> + Debug) -> Result<()> {
294+
async fn send_raw(&self, bytes: impl Into<Vec<u8>> + Debug) -> Result<()> {
295295
Ok(self.ws_sink.lock().await.send(Message::Binary(bytes.into())).await?)
296296
}
297297

0 commit comments

Comments
 (0)