Skip to content

Rename AllocRef to Allocator and alloc to allocate #76

Closed
rust-lang/rust
#79286
@TimDiekmann

Description

@TimDiekmann

With rust-lang/rust#77187 we released AllocRef to the wild. It was pointed out, the names AllocRef and alloc are confusing sometimes. The main reason for this, is, that "alloc" is used as a verb and as a noun.

in rust-lang/rust#77187 (comment) @Aaron1011 noted, that:

[Box::alloc_ref] sounds like we're allocating a reference, not obtaining a reference to the allocator.

However, alloc_ref is the lowercased name of the Trait. @Amanieu also suggested, to rename it to Box::allocator, but the term allocator is never used anywhere, so I decided to stick with alloc_ref for now.

I think, it makes sense, to rename AllocRef to Allocator and (de)alloc to (de)allocate. The main reason for calling it AllocRef instead of Alloc was, that we wanted to express, that AllocRef should be a ZST or a reference to the actual allocator (not a reference to an "alloc" 😉 ). This however is also pointed out in the documentation and we don't expect many people to implement an allocator.
A very minor downside is the longer name of Allocator and allocate, but it's way more clear, if you read those terms. The trait will also not be used often directly. In most cases, it will simply be passed to Box or Vec. So most people neither have to call allocate or deallocate, nor have to import Allocator into scope. They probably won't even care, how the allocator is implemented (ZST or reference) as long they can simply pass an allocator to those structs.

This proposal also includes renaming Box::alloc_ref to Box::allocator.

cc @Amanieu @Lokathor @Wodann @CAD97 @scottjmaddox @vertexclique

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions