once_cell icon indicating copy to clipboard operation
once_cell copied to clipboard

Support slices in `OnceRef` and `OnceBox`

Open nvzqz opened this issue 2 years ago • 4 comments

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.

nvzqz avatar Aug 10 '23 14:08 nvzqz

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

notgull avatar Aug 10 '23 15:08 notgull

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

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

matklad avatar Aug 10 '23 15:08 matklad

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 avatar Aug 10 '23 15:08 nvzqz

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

nvzqz avatar Aug 10 '23 15:08 nvzqz