Open ivannp opened 3 years ago
Given that Allocator
is almost object-safe, yes it should. Currently, the only thing holding it back is Allocator::by_ref
which uses Self
in its signature. If that is given a where Self: Sized
bound, then Allocator
will become object safe, so you can use it polymorphically.
Please do send a PR for this, otherwise we might forget about it before stabilizing Allocator
.
Would the allocator type in this case be &dyn Allocator
, or something else?
&dyn Allocator
, Box<dyn Allocator>
, Arc<dyn Allocator>
, etc.
Since rust-lang/rust#81730 was merged, can this issue be closed?
How is the scenario where the allocator is, and can only be, determined at runtime supported? Not too advanced in Rust, so I might be missing something obvious.
I am kind of looking for the equivalent to the C++ 17 polymorphic allocators. In this scenario, the allocator can literally be dropped from the template definition, and it's determined at runtime, via the constructor. This is common scenario in systems using different heaps for different allocations. In these cases, the common scenario is to have a single allocator type, with different runtime configs: