{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreifwosnexxhb6kuv7jzlug6scga4lknz7qkj5ryt65m35w2oys37km",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mmpeuv26am52"
},
"path": "/t/what-is-allocator-by-ref-for/24356#post_8",
"publishedAt": "2026-05-25T20:44:31.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "`Iterator::by_ref` is useful because many of the methods take `self`, especially when creating new adaptors, but there is also the blanket impl on `&mut I` so you can have those capture a reference instead via `iter.by_ref().foo()` -- or equally `(&mut iter).foo()`. `io::Read::by_ref` is similar since there are `self` methods for adaptors.\n\n`io::Write` and `Allocator` also have similar blanket impls, but they don't have _any_ `self`-consuming methods AFAICS, so I don't know why we should want `by_ref()`. I only found two existing uses of `Allocator::by_ref` in `Arc`/`Rc::from_box_in`, and both would be more succinct to use `&alloc`.",
"title": "What is Allocator::by_ref for?"
}