What is Allocator::by_ref for?
Rust Internals [Unofficial]
May 25, 2026
That’s not a good reason to have it for Allocator, though. I can see that someone might want to pass &MyAllocator when constructing a container, but that will never be a method chain.
According to the revision history, by_ref was added in Add a "by reference" adaptor for AllocRef by TimDiekmann · Pull Request #71442 · rust-lang/rust · GitHub, which was primarily about adding the &A (at the time, &mut A) implementation. The issue mentions adding by_ref by analogy with io::Write::by_ref(). Which seems to me to be a method with equally little reason to exist, but perhaps I am missing something.
Discussion in the ATmosphere