danielhenrymantilla / rust-uninit

Read trait fixed to soundly work with uninitalized memory
MIT License
25 stars 2 forks source link

`impl<'out, T: 'out, const N: usize> Deref for Out<'out, [T; N]>` #29

Closed kupiakos closed 10 months ago

kupiakos commented 10 months ago

So Out<[T; N]> is less of a second-class citizen. The indexing operations have the same concern.

The initial plan is type Target = [T], though Target = [T; N] would be the more purely correct option. This should compare the documentation ergonomics of the two.

kupiakos commented 10 months ago

This should compare the documentation ergonomics of the two.

It appears that if you have two Deref with different type Target, my version of rustdoc will only include the "methods from Deref" for the last declared Deref. It might be a footgun to have [T; N] not mention all of the available methods in its rustdoc, e.g. .as_slice().

kupiakos commented 10 months ago

I've yanked 2a973ec from the tree: turns out it causes some very nasty type ambiguities that I would much rather do without. Further options are discussed in #31.

kupiakos commented 10 months ago

The extra trait bounds seem right in theory, but make surrounding code break without explicitly spelling everything out:

impl<'out, T, U> ::core::ops::Deref for Out<'out, T>
where
    T: ?Sized + AsMaybeUninit,
    T::Uninit: core::ops::Deref<Target = [MaybeUninit<U>]>
{
    type Target = [MaybeUninit<U>];

    #[inline]
    fn deref(&self) -> &[MaybeUninit<U>] {
        self.as_uninit().deref()
    }
}