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

Suggestion: allow the constructors without _in for allocator types that implement Default #127

Open
Rua opened this issue Jun 7, 2024 · 2 comments

Comments

@Rua
Copy link

Rua commented Jun 7, 2024

In my case, the allocator is just an empty struct that calls global functions, but it's not the global allocator. Having to pass Default::default() to every constructor is awkward. Is it possible to make the standard constructors like new, new_uninit etc available to non-standard allocators if the allocator implements Default? Then I can just do this:

type MyBox<T> = Box<T, MyAllocator>;
MyBox::new(foo)
@Amanieu
Copy link
Member

Amanieu commented Jun 14, 2024

Unfortunately we can't make this change because it would break type inference for a huge portion of the ecosystem. This is the same reason why HashMap::new only works with the default hasher, even if you are using a custom hasher that implements Default.

@CAD97
Copy link

CAD97 commented Jun 16, 2024

Highly relevant: Gankra's article Defaults Affect Inference in Rust: Expressions Instead Of Types

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