matklad / once_cell

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

Support slices in `OnceRef` and `OnceBox` #246

Closed nvzqz closed 1 week ago

nvzqz commented 1 year ago

This is implemented through a new public-in-private OncePointee trait. If this was instead done with impl OnceRef<[T]>, the compiler fails to infer which methods we want to use.

Because of the usage of core::ptr::slice_from_raw_parts in const, this change increases the MSRV to 1.64.0.

To make correctness easier to reason about, I did not use Ordering::Relaxed. However, it's likely that this code could be improved by it.

notgull commented 1 year ago

I would discourage bumping the MSRV past 1.63, as that is the current MSRV for Debian Stable

matklad commented 1 year ago

Compatibility with Debian stable is an explicit non-goal for once_cell:

https://github.com/matklad/once_cell/issues/201#issuecomment-1254883343

nvzqz commented 1 year ago

I can rewrite this to use an associated type via OncePointee instead of UnsafeCell<*mut T>. That should remove the need to bump the MSRV.

nvzqz commented 1 year ago

@notgull I refactored the code to only require bumping to 1.61.0.

matklad commented 1 week ago

closing as per https://github.com/matklad/once_cell/pull/246#discussion_r1299254344