Skip to content

Allow accessing the inner ArrayVec of a SequenceOf #665

Closed

Description

@ChristopherRabotin

Hi Tony,

Unless I'm mistaken, in der version 0.6, the inner field of a SequenceOf struct is not public: would it be possible to get a mutable pointer to that ArrayVec? From that, I think I should be able to call any of the methods of slice (e.g. the sort method) on the underlying data since it implements the AsRef structure. Is that correct?

My use case is the following: I am building a lookup table of u32s, stored as a SequenceOf<u32, 256>. Prior to encoding it, I want to ensure it's sorted so I can do a binary search on that data upon loading it.

Another option would be for me to store the data as an ArrayVec and then initialize the SequenceOf from that ArrayVec (probably by moving the data) when encoding it, but that seems less straightforward.

Thanks for your help

Activity

  1. tarcieri commented on May 22, 2022

    @tarcieri
    Member

    Are you specifically trying to avoid heap allocations? If not, then you can use Vec<u32> instead.

  2. ChristopherRabotin commented on May 22, 2022

    @ChristopherRabotin
    ContributorAuthor
  3. tarcieri commented on May 22, 2022

    @tarcieri
    Member

    Right now the ArrayVec type isn't part of the public API. That's intentional as it enables changing the backing storage without making breaking changes to the API.

    I would prefer not to expose the current implementation. If we do expose it, I'd prefer to use either a crate like arrayvec or tinyvec, or a prospective implementation in core.

  4. ChristopherRabotin commented on May 22, 2022

    @ChristopherRabotin
    ContributorAuthor

    That makes sense.

    I might not get around to it until a bit, but would the goal be to replace the ArrayVec with one of the equivalents from arrayvec or tinyvec? A quick glance seems to indicate that tinyvec is more feature-full compared to arrayvec's equivalent. Do you have any preference? I would opt for tinyvec if I were to make the changes, unless you object of course.

  5. tarcieri commented on May 22, 2022

    @tarcieri
    Member

    It might be possible. It would require some investigation, and is likely to require breaking changes, which I'd prefer not to make for awhile as I just cut a der v0.6 release and am slowly getting everything transitioned to use it.

    I would have a weak preference for tinyvec as it uses no unsafe code.

    Also: at present der has no hard dependencies and I'd prefer to keep it that way, so if we were to add it I'd prefer it be optional like the rest of the dependencies.

  6. tarcieri commented on Feb 11, 2026

    @tarcieri
    Member

    Closing in favor of #2218: we should probably replace our naive internal ArrayVec implementation with a well-maintained optional third party crate. If we do that, I have no problem exposing the inner type: we could do AsRef or what have you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions