Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow accessing the inner ArrayVec of a SequenceOf #665

Open
ChristopherRabotin opened this issue May 22, 2022 · 5 comments
Open

Allow accessing the inner ArrayVec of a SequenceOf #665

ChristopherRabotin opened this issue May 22, 2022 · 5 comments

Comments

@ChristopherRabotin
Copy link
Contributor

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

@tarcieri
Copy link
Member

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

@ChristopherRabotin
Copy link
Contributor Author

ChristopherRabotin commented May 22, 2022 via email

@tarcieri
Copy link
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.

@ChristopherRabotin
Copy link
Contributor Author

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.

@tarcieri
Copy link
Member

tarcieri commented May 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants