As for runtime injection rather than type parametrization, the problem is
Drop . The type has to know how to dealloc itself at an arbitrary timing, without outside input. Also, providing the wrong de/alloc to an allocating method would be super quick UB.
I know this is a bit off topic, but I would love for the ability to have a Drop (or a required consuming
self method) with custom parameters that had to be explicitly called or would be a compile error. This would allow something like the following to be a compile error:
fn do_a_thing(device: &mut Device)
let mut command_buffer = CommandBuffer::new();
// ERROR: oops forgot to call `command_buffer.execute(device);`.
This would be a compile error because the following couldn't be automatically called due to requiring more than just
impl Drop for CommandBuffer
fn drop(&mut self, device: &mut Device)
Back to the allocation subject, if this functionality existed, then you could require the allocator be passed to
Drop instead of storing it on the instance. At the same time, a type that stores the allocator wouldn't require that and could just use the implicit Drop call.