External Publication
Visit Post

What is Allocator::by_ref for?

Rust Internals [Unofficial] May 25, 2026
Source

I was looking at the Allocator API that is currently being stabilized and noticed that it has an Allocator::by_ref method.

I don't really understand what that method is for. It seems to simply return a shared reference to the allocator, so how is it any different from a simple borrow? Also the documentation for by_ref talks about returning an adapter of some kind, which it clearly does not do.

I would appreciate any insight or further reading on why this method exists and what the documentation is talking about.

Discussion in the ATmosphere

Loading comments...