Skip to content

refactor!: replace lazy_static with std::sync::OnceLock#127

Merged
erenatas merged 3 commits intomainfrom
erenatas/wasm-compat
Feb 24, 2026
Merged

refactor!: replace lazy_static with std::sync::OnceLock#127
erenatas merged 3 commits intomainfrom
erenatas/wasm-compat

Conversation

@erenatas
Copy link
Contributor

@erenatas erenatas commented Feb 23, 2026

This PR

This change enables Webassembly compatibility by replacing lazy_static with syd::sync:OnceLock and tokio feature changes. It should be considered breaking due MSRV change.

This change doesn't have any performance impact on the library itself. tokio's sync feature provides RwLock which works identically regardless of runtime. Users of this library can enable tokio's multi-threaded runtime if needed.

Changes in summary:

  • Replace lazy_static crate with std::sync::OnceLock for singleton
  • Bump MSRV from 1.77.0 to 1.80.1
  • Remove lazy_static dependency
  • Split tokio features: sync for library, rt-multi-thread/macros for tests
  • Update doc comment to reference public API methods

Related Issues

This change is the first follow up from comments over Slack regarding web assembly compatibility requests

This change enables Webassembly compatibility by replacing `lazy_static` with `syd::sync:OnceLock`
and tokio feature changes. It should be considered breaking due MSRV change.

This change doesn't have any performance impact on the library itself. tokio's `sync` feature provides
`RwLock` which works identically regardless of runtime. Users of this library can enable tokio's multi-threaded
runtime if needed.

Changes in summary:
- Replace lazy_static crate with std::sync::OnceLock for singleton
- Bump MSRV from 1.77.0 to 1.80.1
- Remove lazy_static dependency
- Split tokio features: sync for library, rt-multi-thread/macros for tests
- Update doc comment to reference public API methods

Signed-off-by: Eren Atas <eren.atas@booking.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @erenatas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the library's singleton initialization mechanism by migrating from the lazy_static crate to std::sync::OnceLock, a change crucial for achieving WebAssembly compatibility. It also refines Tokio feature usage for better modularity and updates the minimum supported Rust version, which is a significant breaking change for consumers of the library.

Highlights

  • WebAssembly Compatibility: The primary goal of this change is to enable WebAssembly compatibility for the library.
  • Singleton Implementation: Replaced the lazy_static crate with Rust's standard library std::sync::OnceLock for managing the OpenFeature singleton instance.
  • Minimum Supported Rust Version (MSRV): Bumped the MSRV from 1.77.0 to 1.80.1, which is considered a breaking change.
  • Tokio Feature Management: Refactored Tokio features, specifying sync for the library and sync, rt-multi-thread, and macros for tests to provide more granular control and reduce unnecessary dependencies.
  • Documentation Updates: Updated doc comments to reflect the new singleton access methods.
Changelog
  • Cargo.toml
    • Updated the rust-version from 1.77.0 to 1.80.1.
    • Removed the lazy_static dependency.
    • Modified tokio dependency features from full to sync for the main library.
    • Added a separate tokio dependency for development/test purposes with sync, rt-multi-thread, and macros features.
  • src/api/api.rs
    • Replaced lazy_static import with std::sync::OnceLock.
    • Changed the SINGLETON static variable from lazy_static! macro to OnceLock<RwLock<OpenFeature>>.
    • Introduced a new private function singleton_lock() to initialize and retrieve the RwLock<OpenFeature> instance using OnceLock.
    • Updated OpenFeature::singleton() and OpenFeature::singleton_mut() methods to use the new singleton_lock() function.
    • Adjusted doc comments to reference the new singleton access pattern.
Activity
  • This change is a direct follow-up to discussions on Slack regarding WebAssembly compatibility requests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly replaces lazy_static with std::sync::OnceLock to improve WebAssembly compatibility and modernize the codebase. The changes also include a sensible split of tokio features between library dependencies and development dependencies, which is a great improvement. The implementation of the singleton pattern using OnceLock is correct and thread-safe. I have one suggestion to improve the naming of a helper function for better clarity.

erenatas and others added 2 commits February 23, 2026 21:38
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Eren Atas <sovairon@gmail.com>
Signed-off-by: Eren Atas <eren.atas@booking.com>
Copy link
Member

@jonathannorris jonathannorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, scoping tokio should help with WASM support.

@erenatas erenatas merged commit 8d9182a into main Feb 24, 2026
10 checks passed
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.

2 participants