Skip to content

Commit 8538dbf

Browse files
author
Daniel Giribet Farre
committed
addressed some clippy warnings
1 parent 9a3749f commit 8538dbf

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/brokers/surrealdb/utils.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -205,32 +205,30 @@ fn index_table(queue_name: &str) -> String {
205205
format!("{queue_name}___index")
206206
}
207207

208-
/// time+id range record id, namely queue_table:[when,<uuid>task_id]
208+
/// time+id range record id, namely `queue_table`:[when,<uuid>`task_id`]
209209
fn queue_record_id(queue_name: &str, when: &str, task_id: &str) -> Result<RecordId, BroccoliError> {
210210
// TODO: look at building the record programmatically, move when to typed
211211
// compromise here is that we do explicit casting of the uuid, if it's not correct it will fail
212212
let queue_table = self::queue_table(queue_name);
213-
let queue_record_str = format!("{}:[{},<uuid>'{}']", queue_table, when, task_id);
213+
let queue_record_str = format!("{queue_table}:[{when},<uuid>'{task_id}']");
214214
let queue_record_id = RecordId::from_str(&queue_record_str);
215215
match queue_record_id {
216216
Ok(record_id) => Ok(record_id),
217217
Err(e) => Err(BroccoliError::Broker(format!(
218-
"Incorrect task id for queue ({})",
219-
e
218+
"Incorrect task id for queue ({e})"
220219
))),
221220
}
222221
}
223222

224-
/// index_table:[<uuid>task_id, queue_name]
223+
/// `index_table`:[<uuid>`task_id`, `queue_name`]
225224
fn index_record_id(task_id: &str, queue_name: &str) -> Result<RecordId, BroccoliError> {
226225
let index_table = self::index_table(queue_name);
227-
let index_record_str = format!("{}:[<uuid>'{}','{}']", index_table, task_id, queue_name);
226+
let index_record_str = format!("{index_table}:[<uuid>'{task_id}','{queue_name}']");
228227
let index_record_id = RecordId::from_str(&index_record_str);
229228
match index_record_id {
230229
Ok(record_id) => Ok(record_id),
231230
Err(e) => Err(BroccoliError::Broker(format!(
232-
"Incorrect task id for index ({})",
233-
e
231+
"Incorrect task id for index ({e})"
234232
))),
235233
}
236234
}
@@ -304,18 +302,17 @@ async fn add_record_to_queue(
304302
})
305303
.await
306304
.map_err(|e: surrealdb::Error| {
307-
BroccoliError::Broker(format!("{}:'{}': {}", err_msg, queue_name, e))
305+
BroccoliError::Broker(format!("{err_msg}:'{queue_name}': {e}"))
308306
})?;
309307
match qm {
310308
Some(_) => {
311309
// now we insert into the index and we are done, note we insert the queue id
312-
let _ = self::add_to_queue_index(&db, queue_name, task_id, queue_record_id, err_msg)
313-
.await?;
310+
let () =
311+
self::add_to_queue_index(db, queue_name, task_id, queue_record_id, err_msg).await?;
314312
Ok(())
315313
}
316314
None => Err(BroccoliError::Broker(format!(
317-
"{}:'{}': adding to queue (silently did not add)",
318-
err_msg, queue_name,
315+
"{err_msg}:'{queue_name}': adding to queue (silently did not add)",
319316
))),
320317
}
321318
}
@@ -326,7 +323,7 @@ async fn add_record_to_queue(
326323
async fn add_to_queue_index(
327324
db: &Surreal<Any>,
328325
queue_name: &str,
329-
task_id: &String,
326+
task_id: &str,
330327
queue_id: RecordId, // queue:[timestamp, task_id]
331328
err_msg: &'static str,
332329
) -> Result<(), BroccoliError> {
@@ -338,13 +335,12 @@ async fn add_to_queue_index(
338335
.content(InternalSurrealDBBrokerQueueIndex { queue_id })
339336
.await
340337
.map_err(|e: surrealdb::Error| {
341-
BroccoliError::Broker(format!("{}:'{}': {}", err_msg, queue_name, e))
338+
BroccoliError::Broker(format!("{err_msg}:'{queue_name}': {e}"))
342339
})?;
343340
match qm {
344341
Some(_) => Ok(()), // happy path
345342
None => Err(BroccoliError::Broker(format!(
346-
"{}:'{}': adding to index (silently did not add)",
347-
err_msg, queue_name,
343+
"{err_msg}:'{queue_name}': adding to index (silently did not add)",
348344
))),
349345
}
350346
}
@@ -362,7 +358,7 @@ async fn get_queue_index(
362358
.select(index_record_id)
363359
.await
364360
.map_err(
365-
|e: surrealdb::Error| BroccoliError::Broker(format!("{}:'{}': {}", err_msg, queue_name, e)),
361+
|e: surrealdb::Error| BroccoliError::Broker(format!("{err_msg}:'{queue_name}': {e}")),
366362
)?;
367363
Ok(queue_index)
368364
}

tests/edge_cases.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ lazy_static! {
196196
static ref succeeded: Arc<tokio::sync::Mutex<usize>> = Arc::new(Mutex::new(0));
197197
}
198198

199-
async fn process_job(msg: TestMessage) -> Result<(), BroccoliError> {
199+
async fn process_job(_: TestMessage) -> Result<(), BroccoliError> {
200200
// helper function to test process_messages
201201
let mut lock = handled.lock().await;
202202
*lock += 1;
@@ -325,9 +325,8 @@ async fn test_ttl_not_implemented() {
325325
.publish(test_topic, None, &message, Some(options))
326326
.await;
327327

328-
match result {
329-
Ok(_) => assert!(false, "Should be unimplemented"),
330-
Err(_) => assert!(true),
328+
if result.is_ok() {
329+
panic!("Should be unimplemented")
331330
}
332331
}
333332

0 commit comments

Comments
 (0)