External Publication
Visit Post

What is Allocator::by_ref for?

Rust Internals [Unofficial] May 26, 2026
Source

rne:

What's the benefit of these kind of associated functions over impl AsMut<Self> for ...?

Avoiding amiguity for the sake of inference.

rne:

And, having AsRef and AsMut in mind, why is it called by_ref and not by_mut although it returns a mutable reference?

Perhaps (in the case of Iterator) it's as simple as, it only makes sense for &mut. (OTOH it's a 1.0 method, there may not have been much conversation. I didn't dig.)

Discussion in the ATmosphere

Loading comments...