Skip to content

Commit d60090b

Browse files
authored
fix: remove unsafe code (#64)
1 parent 1efe89a commit d60090b

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ anyhow = "1"
2222
base64 = "0.22"
2323
bon = "3"
2424
clap = { version = "4", features = ["derive"] }
25-
debug_unsafe = "0.1"
2625
hmac = "0.12"
2726
reqwest-retry = "0.7"
2827
serde = { version = "1", features = ["derive"] }

typesense/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ typesense_derive = { workspace = true, optional = true }
2222
anyhow = { workspace = true }
2323
base64 = { workspace = true }
2424
bon = { workspace = true }
25-
debug_unsafe = { workspace = true }
2625
hmac = { workspace = true }
2726
reqwest-retry = { workspace = true }
2827
serde = { workspace = true }

typesense/src/client/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ use reqwest_middleware::ClientBuilder as ReqwestMiddlewareClientBuilder;
142142
use reqwest_retry::RetryTransientMiddleware;
143143
pub use reqwest_retry::policies::ExponentialBackoff;
144144

145-
use debug_unsafe::{option::OptionUnwrapper, slice::SliceGetter};
146145
use serde::{Serialize, de::DeserializeOwned};
147146
use std::{
148147
future::Future,
@@ -257,7 +256,7 @@ impl Client {
257256
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
258257
.build();
259258

260-
if url.len() > 1 && url.chars().last().unwrap_safe_unchecked() == '/' {
259+
if url.len() > 1 && matches!(url.chars().last(), Some('/')) {
261260
url.pop();
262261
}
263262

@@ -294,8 +293,10 @@ impl Client {
294293
/// Selects the next node to use for a request based on health and priority.
295294
fn get_next_node(&self) -> &Node {
296295
// if only one node (including nearest)
297-
if self.nodes.len() == 1 {
298-
return self.nodes.first().unwrap_safe_unchecked();
296+
if self.nodes.len() == 1
297+
&& let Some(first) = self.nodes.first()
298+
{
299+
return first;
299300
}
300301

301302
let (nodes_len, mut index) = if self.is_nearest_node_set {
@@ -309,7 +310,7 @@ impl Client {
309310
};
310311

311312
for _ in 0..self.nodes.len() {
312-
let node = self.nodes.get_safe_unchecked(index);
313+
let node = &self.nodes[index];
313314

314315
if node.is_healthy.load(Ordering::Relaxed)
315316
|| node.last_accessed.read().unwrap().elapsed() >= self.healthcheck_interval
@@ -322,7 +323,7 @@ impl Client {
322323
// If all nodes are unhealthy and not due for a check, just pick the next one in the round-robin.
323324
// This gives it a chance to prove it has recovered.
324325
index = self.current_node_index.load(Ordering::Relaxed) % self.nodes.len();
325-
self.nodes.get_safe_unchecked(index)
326+
&self.nodes[index]
326327
}
327328

328329
/// For use in legacy APIs.

0 commit comments

Comments
 (0)