What is Allocator::by_ref for?
Rust Internals [Unofficial]
May 26, 2026
rne:
What's the benefit of these kind of associated functions over
impl AsMut<Self> for ...?
these are trait methods. (for example on Iterator), so as_ref is available on every iterator and only on iterators. you cannot impl<I : Iterator> AsMut<Self> for I, that would be against the orphan rule. AsMut ofc is not reflexive.
BorrowMut is relexive, but then it is on every type and can get noisy, as well as conflict with inherent methods.
Discussion in the ATmosphere