hypermine
hypermine copied to clipboard
Modernize Rust idioms
Tracking minor cosmetic improvements enabled by recent changes to Rust:
- [x] Replace
.iter().copied()on arrays with.into_iter() - [x] Replace
lazy_staticwith const logic where possible, and otherwiseOnceLock(or eventuallyLazyLock, once stabilized) - [ ] Replace default-then-linearly-overwrite array construction patterns with
array::from_fn
What's the right way to make a lazy OnceLock as of now? Lazy<OnceLock<_>> or OnceLock<Lazy<_>>?
I don't know what the Lazy you're referring to is.
once_cell::sync::Lazy
I tried to use a OnceCell for the static values and was suggested by rustc to wrap the whole thing in Lazy::new(||). Since I don't think OnceLock can be initialized statically, I think Lazy<OnceLock<_>> is the right option. Though now every time I access the static values I have to uset .get().unwrap() first...
Here's a bigger problem with Lazy<OnceLock<_>>...
cannot return value referencing temporary value
returns a value referencing data owned by the current function
Now I have to lazify everything, I guess...
We shouldn't introduce a dependency on once_cell. OnceLock is part of std. The documentation illustrates how to use it in a static.
I think using const logic would still be a bit painful due to being unable to use iterators (so we should probably avoid it for now to avoid potential burnout). OnceLock seems promising, though.
I think there's at least a handful of low hanging fruit that don't use iterators. Definitely no need to force the issue, though. A more serious limitation might be the missing transcendental operations on floats.