matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.84k stars 110 forks source link

Add from_fn #227

Closed dspyz-matician closed 1 year ago

dspyz-matician commented 1 year ago

Sometimes the compiler fails to infer the type of T in a Lazy. This helps the compiler figure it out from the closure.

matklad commented 1 year ago

Hm, I am torn a bit... Ideally, we'd just add this bound to new, like we do for std.

That would be an incompatible change though (the reason why we don't have this bound is that it was impossible until some relatively recent version of Rust)

I don't want to break semver by adding the bound retroactively, but I am also not sure that adding a whole new method here is justified...

matklad commented 1 year ago

To not let this hang indefinitely, I decided to close this: to me it seems that smaller API surface outweighs reduced annotation burden.