rust-lang / wg-allocators

Home of the Allocators working group: Paving a path for a standard set of allocator traits to be used in collections!
http://bit.ly/hello-wg-allocators
203 stars 9 forks source link

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

Open Rua opened 1 month ago

Rua commented 1 month ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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