-
-
Notifications
You must be signed in to change notification settings - Fork 153
lazy_static init method substituted with once_cell lazy type #363
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
lazy_static init method substituted with once_cell lazy type #363
Conversation
1.utilizing Lazy type for init wherever possible 2.for more types where static types demand some implementation a child struct is created to accomodate the values of the inner and type and traits Deref, DerefMut & Debug are explicitly implemented
|
Thanks @artech-git . cc @trueleo can you take a look |
We already have derive_more in the dependencies which provides derive macros for Deref and DerefMut, I made some changes to your branch and pushed a PR. artech-git#1 , Accept these changes and i think this is good to merge. |
use derive_more instead of manual impl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
|
Thanks @trueleo for bringing that to my knowledge 😊, also there was one smoke test failing for docker-compose can you educate me what that is about ? |
Hey @artech-git this is a Docker compose based test which is a little flaky sometimes. We need to fix the CI. I tested the PR locally, seems to be working fine. Merging this now |
Thanks for the info |
Description
In My understanding using lazy_static with some subtle ways to implement a feature is not very idiomatic to write code
To eliminate the Usage for Lazy_static on runtime initialization, which can be directly accomplished through once_cell
and makes our implementation more clear.
Though there are multiple crates available to perform global runtime initialization method, but using the one already in the project (which is once_cell) is suitable for this improvement.
replaced with the following method
since the
Lazy<T,F>implements Deref & DerefMut traits we can directly call the methods for the types present under itbut for some types which require a
std::fmt::Debugimplementation and also have some standalone implementation for itwhat I refactored to
I first concealed the type into a child struct and implemented Deref and DerefMut on it so that we call methods directly
and since Lazy type already implements Deref traits so it directly call the appropiate method without any problem through out the rest of the code
If you find something missing or these changes won't be according to your standards or just anything which is necessary and seems missing in my knowledge do let me know 😊 I will be more than happy to revise my work.
It will nice if someone can please test and verify the below marked parameters to ensure these changes won't cause any undefined behavior
This PR has: