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

Missing Clone for Box #204

Open
douglas-raillard-arm opened this issue Apr 11, 2023 · 3 comments
Open

Missing Clone for Box #204

douglas-raillard-arm opened this issue Apr 11, 2023 · 3 comments

Comments

@douglas-raillard-arm
Copy link

Bumpalo's Box is missing a Clone implementation, which is a pretty big departure from std's Box. Bringing it back would require storing a &Bump inside the Box in addition to the &mut T to be able to allocate a new value inside the same arena.

That is also the way std is implemented:
https://doc.rust-lang.org/src/alloc/boxed.rs.html#198-201

@fitzgen
Copy link
Owner

fitzgen commented Apr 21, 2023

This was intentional to keep bumpalo::boxed::Box a single word.

@douglas-raillard-arm
Copy link
Author

Maybe that could become opt-in with a generic parameter, defaulting to current behavior ? Something like:

pub struct Box<'a, T: ?Sized, Alloc=()>(&'a mut T, alloc: Alloc);

type CloneableBox<'a, T> = Box<'a, T, &'a Bump>;

impl<'a, T: ?Sized> Clone for Box<'a, T, &'a Bump> {
      ...
}

@rzvxa
Copy link

rzvxa commented Sep 6, 2024

In oxc, we achieve this with a CloneIn trait.

https://github.com/oxc-project/oxc/blob/main/crates/oxc_allocator/src/clone_in.rs something similar might be useful to you.

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

3 participants