This has several advantages:
AllocRef can now be used by concurrent (lock-free) data structures which only have &self operations. Currently the allocator would need to be wrapped in a mutex even if the allocator is thread-safe.
- Allocators can directly expose whether they are thread-safe or not with
Sync. This bound is inherited by data structures using an allocator: a lock-free queue would only be Sync if its allocator is Sync.
We can define a blanket implementation of AllocRef for all types implementing GlobalAlloc. This would allow us to change #[global_allocator] to require AllocRef instead of GlobalAlloc. This is not possible if AllocRef methods take &mut self.
This has several advantages:
AllocRefcan now be used by concurrent (lock-free) data structures which only have&selfoperations. Currently the allocator would need to be wrapped in a mutex even if the allocator is thread-safe.Sync. This bound is inherited by data structures using an allocator: a lock-free queue would only beSyncif its allocator isSync.We can define a blanket implementation ofAllocReffor all types implementingGlobalAlloc. This would allow us to change#[global_allocator]to requireAllocRefinstead ofGlobalAlloc. This is not possible ifAllocRefmethods take&mut self.