Skip to content

Unflatten trait limitations #174

Description

@Vidi0

Currently, this is the definition of the Unflatten trait:

pub unsafe trait Unflatten<T, NM, N>: GenericSequence<T, Length = NM>
where
    NM: ArrayLength + Div<N>,
    N: ArrayLength,
    Quot<NM, N>: ArrayLength,
{
    type Output: GenericSequence<GenericArray<T, N>, Length = Quot<NM, N>>;

    fn unflatten(self) -> Self::Output;
}

However, sometimes I need to split a GenericSequence into M parts of length N instead of splitting a GenericSequence of length NM into parts of length N. The existing trait computes the chunk count via division, but I already know both dimensions in advance. While both ideas seem similar, the problem I have noticed with the current trait is that it doesn't allow for N = UTerm, whereas the other trait would. This is required for my use case of parsing an array of ZSTs, where I know the number and the size (0) of the ZSTs, but the Unflatten trait won't allow running unflatten on that.

For this reason, I propose adding a new trait with the following signature (rather than modifying the current one, as this would break compatibility):

pub unsafe trait UnflattenChunks<T, N, M>: GenericSequence<T, Length = Prod<N, M>>
where
    M: ArrayLength,
    N: ArrayLength + Mul<M>,
    Prod<N, M>: ArrayLength,
{
    type Output: GenericSequence<GenericArray<T, N>, Length = M>;

    fn unflatten(self) -> Self::Output;
}

(The name of the new trait could be changed, I'm not good at naming things).

P.S. Thank you for the crate, I think it's very cool, and I've been enjoying programming with it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions