Skip to content

Replace lazy_static with std::sync::LazyLock#498

Merged
gcomte merged 1 commit intomasterfrom
fix/replace-lazy-static
Mar 30, 2026
Merged

Replace lazy_static with std::sync::LazyLock#498
gcomte merged 1 commit intomasterfrom
fix/replace-lazy-static

Conversation

@gcomte
Copy link
Copy Markdown
Owner

@gcomte gcomte commented Mar 30, 2026

Summary

  • Replace lazy_static! macro with std::sync::LazyLock (stable since Rust 1.80)
  • Remove lazy_static crate dependency

Test plan

  • cargo check passes
  • CI build + tests pass

Summary by CodeRabbit

  • Refactor
    • Removed an external dependency and modernized the lazy initialization mechanism by switching to a built-in standard library alternative. This reduces external dependencies, improves code maintainability, and ensures all existing functionality remains intact with no user-facing impact.

LazyLock is stable since Rust 1.80. Removes one dependency.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16140f98-1773-4e15-b1a7-39625f8beb24

📥 Commits

Reviewing files that changed from the base of the PR and between 6fdec08 and 900ce58.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml
  • src/currency/fiat.rs
💤 Files with no reviewable changes (1)
  • Cargo.toml

📝 Walkthrough

Walkthrough

This pull request migrates the EXCHANGE_RATE_PROVIDER static initialization from the external lazy_static crate to Rust's built-in std::sync::LazyLock, eliminating the external dependency while preserving identical functionality.

Changes

Cohort / File(s) Summary
Dependency Removal
Cargo.toml
Removed lazy_static = "1.5.0" from dependencies.
LazyLock Migration
src/currency/fiat.rs
Replaced lazy_static! macro with std::sync::LazyLock for EXCHANGE_RATE_PROVIDER initialization; updated imports to remove lazy_static::lazy_static and add std::sync::LazyLock. Locking behavior in Fiat::btc_value() remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Refactor exchange rate caching #370: Modifies the same EXCHANGE_RATE_PROVIDER initialization in src/currency/fiat.rs, replacing an earlier unsafe static pattern with lazy_static! and Mutex, making this PR a direct successor migration to Rust's built-in LazyLock.

Poem

Lazy static fades away,
LazyLock leads the way! 🐰
Built-in magic, swift and true,
Dependencies, one fewer hue,
Rust's own power sees us through! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Replace lazy_static with std::sync::LazyLock' accurately describes the primary change: migrating from the lazy_static crate to Rust's built-in LazyLock mechanism, including removing the external dependency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/replace-lazy-static

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gcomte gcomte merged commit abaa207 into master Mar 30, 2026
7 of 8 checks passed
@gcomte gcomte deleted the fix/replace-lazy-static branch March 30, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant