Name suggestion when new is taken

⚓ Rust    📅 2026-04-06    👤 surdeus    👁️ 2      

surdeus

When working with non-default allocators, instead of writing say

let v = Vec::new();

you need to have something like

let type LVec<T> = Vec<T,Local>;

let v = LVec::new_in( Local::new() );

Here Local is a zero-size-type that implements Allocator and Default ( so is Global ). This gets a little tiresome, so it is convenient to have an “alternative” new function which uses the default, so you only have to write

let v = LVec::auto();

“auto” is what I thought of initially, it “automatically” creates the default allocator for you. I also have a method with_capacity_auto which is used instead of with_capacity_in. ( See here )

The trouble is “auto” isn’t that good of a name for this, but I am having trouble coming up with something better.

“new” cannot be used for backward-compatibility reasons, it always allocates always from Global, and changing that would mean a lot of changes to existing code (where the Allocator to be used is not specified by the type ). [ I tried then realised later it would not work well! ]

Originally I had a free function lvecbut that doesn’t look similar to Vec::new(), so I think it doesn’t read so well. The same applies to Box, Rc etc.

So I want a short word, that means roughly the same as new, but is reasonably distinctive. Can you think of something better than “auto”? Or is there a better approach altogether?

Some other words I am thinking of : “make”, “create”, “init”, “store”, “with”.

6 posts - 3 participants

Read full topic

🏷️ Rust_feed