You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case that's similar to lazy_static but that cannot be solved nicely right now.
If the default initializer to a lazy_static variable is something that wants arguments at initialization-time, or is something that can fail, then currently the usage is very awkward. Of course it's possible that I'm missing something obvious, I'm very new to Rust still, so apologies in advance if that's the case.
You may well consider this out of scope for this project (wouldn't really be "lazy"), but I wanted to ask before I contemplate if it's worth forking the project.
Basically, what I want would look something like this:
lazy_static!{pubstatic ref QUOTES: QuoteLibrary;
}fnmain(){let filename = "quotes.yaml";matchQuoteLibrary::load_file(filename){// ^^^^^^^^// allows me to provide arguments to the initializer functionOk(quotes) => lazy_static::initialize("ES, quotes);// assigned hereErr(err) => // allows reporting initialization failures nicely}}
The semantics would be:
Any access to QUOTES before it's initialized would panic.
Attempting to set the value multiple times might possibly panic too?
I have a use case that's similar to
lazy_static
but that cannot be solved nicely right now.If the default initializer to a
lazy_static
variable is something that wants arguments at initialization-time, or is something that can fail, then currently the usage is very awkward. Of course it's possible that I'm missing something obvious, I'm very new to Rust still, so apologies in advance if that's the case.You may well consider this out of scope for this project (wouldn't really be "lazy"), but I wanted to ask before I contemplate if it's worth forking the project.
Basically, what I want would look something like this:
The semantics would be:
QUOTES
before it's initialized would panic.This saves me from writing:
and also saves
.lock().unwrap()
calls every time I want to use theQUOTES
value.For context, this is what I initially wrote, when attempting to use the current
lazy_static
:The text was updated successfully, but these errors were encountered: