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

refactor: Use a regular Vec inside BoundedVec, add more tests #680

Closed
wants to merge 2 commits into from

Conversation

vadorovsky
Copy link
Contributor

  • There is no need to use manual allocations in BoundedVec. Instead, we can just embed a regular Vec, make it private and make sure that the methods we expose never reallocate it.
  • Add more test cases covering all error variants.

@vadorovsky vadorovsky requested a review from ananas-block as a code owner May 7, 2024 09:30
@vadorovsky vadorovsky force-pushed the vadorovsky/bounded-vec-refactor-tests branch 5 times, most recently from 17cf033 to 32b89c1 Compare May 7, 2024 12:55
pub struct BoundedVec<'a, T>
/// `Vec` is still used as the underlying data structure, `BoundedVec` exposes
/// only the methods which don't trigger reallocations.
pub struct BoundedVec<T>(Vec<T>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice looks much cleaner and safer now!
The from raw parts makes it zero copy right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the from_raw_parts method from Vec should work the same way (just treat the given raw pointer as a store).

@vadorovsky vadorovsky force-pushed the vadorovsky/bounded-vec-refactor-tests branch 5 times, most recently from 8058300 to 5d0a685 Compare May 10, 2024 09:36
* There is no need to use manual allocations in `BoundedVec`. Instead,
  we can just embed a regular `Vec`, make it private and make sure that
  the methods we expose never reallocate it.
* Add more test cases covering all error variants.
@vadorovsky vadorovsky force-pushed the vadorovsky/bounded-vec-refactor-tests branch from 1726ccc to f2f6963 Compare May 13, 2024 12:46
@vadorovsky vadorovsky marked this pull request as draft May 14, 2024 09:32
@vadorovsky vadorovsky closed this May 17, 2024
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

Successfully merging this pull request may close these issues.

2 participants