Skip to content

Commit 8361b9b

Browse files
chore: upgrade to Rust edition 2024
Edition 2024 makes set_var/remove_var unsafe. Env-var tests are safe because nextest runs each test in its own process. Also applies new rustfmt import ordering and assert macro formatting rules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8f89ca1 commit 8361b9b

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "wokhei"
33
version = "0.3.0"
4-
edition = "2021"
4+
edition = "2024"
55
rust-version = "1.93.1"
66
authors = ["matthiasdebernardini"]
77
license = "MIT"

src/dtag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use nostr_sdk::hashes::{sha256, Hash};
1+
use nostr_sdk::hashes::{Hash, sha256};
22

33
/// Compute a deterministic 8-hex-char suffix from a preimage string.
44
fn suffix(preimage: &str) -> String {

src/error.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,12 @@ mod tests {
229229
fn non_relay_errors_are_not_retryable() {
230230
assert!(!AppError::KeysNotFound { path: "/x".into() }.retryable());
231231
assert!(!AppError::RelayRejected { reason: "x".into() }.retryable());
232-
assert!(!AppError::HeaderNotFound {
233-
event_id: "x".into()
234-
}
235-
.retryable());
232+
assert!(
233+
!AppError::HeaderNotFound {
234+
event_id: "x".into()
235+
}
236+
.retryable()
237+
);
236238
assert!(!AppError::HeaderMissingDTag.retryable());
237239
assert!(!AppError::InvalidEventId { id: "x".into() }.retryable());
238240
assert!(!AppError::NoResults.retryable());

src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,35 +554,38 @@ mod tests {
554554
j["result"]["v"].as_str().unwrap().to_string()
555555
}
556556

557+
// SAFETY: These env-var tests run in separate processes via nextest,
558+
// so there is no concurrent thread that could observe a partial write.
559+
557560
#[test]
558561
fn resolve_relay_default_fallback() {
559-
std::env::remove_var("WOKHEI_RELAY");
562+
unsafe { std::env::remove_var("WOKHEI_RELAY") };
560563
let exec = relay_cli().run_argv(["test", "c"]);
561564
assert!(exec.envelope().ok());
562565
assert_eq!(relay_result(&exec), "ws://localhost:7777");
563566
}
564567

565568
#[test]
566569
fn resolve_relay_flag_override() {
567-
std::env::remove_var("WOKHEI_RELAY");
570+
unsafe { std::env::remove_var("WOKHEI_RELAY") };
568571
let exec = relay_cli().run_argv(["test", "c", "--relay=ws://custom:1234"]);
569572
assert!(exec.envelope().ok());
570573
assert_eq!(relay_result(&exec), "ws://custom:1234");
571574
}
572575

573576
#[test]
574577
fn resolve_relay_env_var() {
575-
std::env::set_var("WOKHEI_RELAY", "ws://envrelay:5555");
578+
unsafe { std::env::set_var("WOKHEI_RELAY", "ws://envrelay:5555") };
576579
let exec = relay_cli().run_argv(["test", "c"]);
577580
assert_eq!(relay_result(&exec), "ws://envrelay:5555");
578-
std::env::remove_var("WOKHEI_RELAY");
581+
unsafe { std::env::remove_var("WOKHEI_RELAY") };
579582
}
580583

581584
#[test]
582585
fn resolve_relay_flag_beats_env() {
583-
std::env::set_var("WOKHEI_RELAY", "ws://envrelay:5555");
586+
unsafe { std::env::set_var("WOKHEI_RELAY", "ws://envrelay:5555") };
584587
let exec = relay_cli().run_argv(["test", "c", "--relay=ws://flagrelay:9999"]);
585588
assert_eq!(relay_result(&exec), "ws://flagrelay:9999");
586-
std::env::remove_var("WOKHEI_RELAY");
589+
unsafe { std::env::remove_var("WOKHEI_RELAY") };
587590
}
588591
}

0 commit comments

Comments
 (0)