Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache result with once_cell #1

Merged
merged 2 commits into from
Jan 22, 2023
Merged

Conversation

rgwood
Copy link
Contributor

@rgwood rgwood commented Jan 22, 2023

Hello! Thanks for creating this crate; I spotted it in my GitHub feed and was quite happy because the older wsl crate has been abandoned. Hopefully is-wsl can be a nice replacement for wsl.

If you're open to PRs, this PR caches the is_wsl() result with once_cell. It's similar to a PR I made for wsl, which was motivated by a situation in Nushell where we want to (frequently) check WSL status before rendering interactive content.

I know it's not ideal to add a dependency, but once_cell is extremely widely used, so much so that it's already in std on nightly. Once it's stabilized, the external dependency will no longer be needed.

I also added an example (cargo run --example main) just to make manual testing a bit easier.

@TheLarkInn
Copy link
Owner

Wow thank you so much for this! I'm going to find some time today to review this!

Adding a crate for caching is a great decision since we should save the work from the file system calls.

@TheLarkInn TheLarkInn self-assigned this Jan 22, 2023
Copy link
Owner

@TheLarkInn TheLarkInn left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for both the example and the optimization!

I'll create an issue for removing once_cell once it goes from nightly => stable in std

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.

None yet

2 participants