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

Add FixedBumpVec::push_in #17

Closed
bluurryy opened this issue May 1, 2024 · 1 comment
Closed

Add FixedBumpVec::push_in #17

bluurryy opened this issue May 1, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@bluurryy
Copy link
Owner

bluurryy commented May 1, 2024

When using a mutable BumpScope you can't have collections referring to the BumpScope at the same time. So you can't have:

struct Foo<'b, 'a> {
    bump: &'b mut BumpScope<'a>,
    vec: BumpVec<'b, 'a, u32>,
}

where vec is allocated in bump.

But you can work around it by using FixedBumpVecs and turning them into a BumpVecs temporarily:

struct Foo<'b, 'a> {
    bump: &'b mut BumpScope<'a>,
    fixed_vec: FixedBumpVec<'a, u32>,
}

impl<'b, 'a> Foo<'b, 'a> {
    fn push(&mut self, value: u32) {
        let Self { bump, fixed_vec } = self;

        let mut vec = core::mem::take(fixed_vec).into_vec(bump);
        vec.push(value);

        *fixed_vec = vec.into_fixed_vec();
    }
}

Let's add push_in(bump, value), so we can just write:

impl<'b, 'a> Foo<'b, 'a> {
    fn push(&mut self, value: u32) {
        self.fixed_vec.push_in(self.bump, value);
    }
}
@bluurryy bluurryy added the enhancement New feature or request label May 1, 2024
@bluurryy
Copy link
Owner Author

This is probably a bad idea. Our api surface is already large, adding another permutation variable (*, *_try, *_in, *_try_in) should have very good reason to exist. Just some sugar like that is not it.

@bluurryy bluurryy closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant